• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Strange generics error

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic