Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

generics: is this possible and with what syntax??

Thread view: 
Joost Kraaijeveld - 30 Nov 2005 11:03 GMT
Hi,

I want to use the concrete type of an outer class as the concrete type
of an inner class but if I do so, I get a warning ( in Eclipse, for some
sample code see below):

"The type parameter ConcreteType is hiding the type ConcreteType"

In other places in my code, in the class outerClass, the member "object"
of the InnerClass is not recognized as being of type ConcreteType, but
*only* as of type AbstractBaseClass, so I assume that warning actaully
means something ;-).

Is what I want possible and if so, what should be the right syntax?

Sample code:

public class OuterClass < ConcreteType extends AbstractBaseClass > {
  // Next line gives the warning
  class InnerClass < ConcreteType extends AbstractBaseClass > {
    ConcreteType object;
  }
}

TIA

Joost
Jaakko Kangasharju - 30 Nov 2005 11:11 GMT
> I want to use the concrete type of an outer class as the concrete type
> of an inner class but if I do so, I get a warning ( in Eclipse, for some
[quoted text clipped - 6 lines]
>   }
> }

Shouldn't you just remove the type parameter from the inner class,
i.e.,

public class OuterClass < ConcreteType extends AbstractBaseClass > {
 class InnerClass {
   ConcreteType object;
 }
}

Because if you want the types to be the same, obviously you need to
share the type.  In your example you could use different classes as
parameters to OuterClass and InnerClass.

Signature

Jaakko Kangasharju, Helsinki Institute for Information Technology
Read excellent fantasy online
http://www.ethshar.com/thesprigganexperiment0.html

Joost Kraaijeveld - 30 Nov 2005 13:31 GMT
Hi Jaakko,

>>I want to use the concrete type of an outer class as the concrete type
>>of an inner class but if I do so, I get a warning ( in Eclipse, for some
[quoted text clipped - 19 lines]
> share the type.  In your example you could use different classes as
> parameters to OuterClass and InnerClass.
Yes, that did it. Thanks for the answer.

Joost
Thomas Hawtin - 30 Nov 2005 12:40 GMT
Joost Kraaijeveld wrote::

> "The type parameter ConcreteType is hiding the type ConcreteType"

> public class OuterClass < ConcreteType extends AbstractBaseClass > {
>   // Next line gives the warning
>   class InnerClass < ConcreteType extends AbstractBaseClass > {
>     ConcreteType object;
>   }
> }

You are defining ConcreteType twice. If InnerClass were a static nested
class, then a different name would be preferable. As it is, you can just
write:

public class OuterClass <CONCRETE extends AbstractBaseClass> {
  class InnerClass {
    CONCRETE object;
  }
}
class AbstractBaseClass {}

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.