Friday, 15 March 2013

java - How to call a generic method directly? -



java - How to call a generic method directly? -

here method calling:

public static <t extends something> group<t> getgroup() { ... }

if wanted store result in variable, this:

group<somethingsubclass> grouping = staticclass.getgroup();

how phone call method without storing in variable?

staticclass.getgroup();

the above tried, unsure (mostly don't think possible way method is) add together generic type t.

solution:

staticclass.<somethingsubclass>getgroup();

you don't need special. invoke as

staticclass.getgroup();

you ignore homecoming value. type argument inferred something, you'd have access in method anyway.

you specify actual type argument doing

staticclass.<sometypethatextendssomething>getgroup();

but don't need since part of method makes utilize of generic type homecoming type, discarding.

java generics

No comments:

Post a Comment