This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange generics error  RSS feed

 
David Nemeskey
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have come across a strange error while using generics. I want to overwrite outerMethod() in the subclasses, and I want to use the type safety provided by generics. There is a sample static subclass called aptly sample. Is there a way to achieve the differently?



The error message I get is a bit absurd... and not helpful at all.


I can change the code, and that solves the problem, but isn't there a better solution?

 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That is correct answer.

If you declare InnerClass<I, O> instead of InnerClass, something like OuterClass<Integer, Integer[]>.InnerClass<String, String[]> is acceptable.

It means that type parameter I, O in OuterClass is different from type parameter I, O in InnerClass, and the compiler complains about this fact.
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Nemeskey:
I can change the code, and that solves the problem, but isn't there a better solution?
Hard to say. What don't you like about that solution? To me it looks better than the original version.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!