Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[haxe.org/manual] Generic #124

Open
utterances-bot opened this issue Dec 15, 2022 · 2 comments
Open

[haxe.org/manual] Generic #124

utterances-bot opened this issue Dec 15, 2022 · 2 comments

Comments

@utterances-bot
Copy link

Generic - Haxe - The Cross-platform Toolkit

Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.

https://haxe.org/manual/type-system-generic.html

Copy link

In Java you can declare that T extends a certain class to ensure the generic type is of that class. E.g. if you have an animal class and a cat class that extends animal, you could make a generic that is Something and now you can use Cat or Animal but not things that aren't Animal extensions for the type of Something.

So... is there equivalent in Haxe for ensuring the T extends something?

@Aurel300
Copy link
Member

@Mimerr you can add constraints to type parameters to specify that they implement or are subclasses of other interfaces/types. For example, the following Java declaration:

public void drawAll(List<? extends Shape> shapes) { ... }

Is roughly equivalent to this Haxe declaration:

public function drawAll<T:Shape>(shapes:List<T>):Void { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants