Date: Fri, 26 Dec 2008 20:47:08 +0100 From: Frank Staals <frankstaals@gmx.net> To: Vladimir Tsvetkov <npacemo@gmail.com> Cc: questions@freebsd.org Subject: Re: Off-topic: Java Reflection/Generics/Collections question Message-ID: <495534BC.1020209@gmx.net> In-Reply-To: <666bdb140812261007p21b23e13k48d80e4a454ce49e@mail.gmail.com> References: <4954E849.6020000@gmx.net> <666bdb140812261007p21b23e13k48d80e4a454ce49e@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Vladimir Tsvetkov wrote: > What you try to do is not a valid operation in type-safe language as > Java. > > You can't convert Coll to Coll<ItemType>, > but you can cast Coll<?> to Coll<Whatever>. > > Don't know if this is OK with the problem you're trying to solve > > Merry Christmas! > > On Fri, Dec 26, 2008 at 4:20 PM, Frank Staals <frankstaals@gmx.net > <mailto:frankstaals@gmx.net>> wrote: > > Not realy a FreeBSD-specific question but I was not sure where I > could find what I was looking for elseware (Googling did not > manage to dig up much info): > > The problem: > > I want to set the type of objects some Collection object holds on > runtime. In other wors I have an object C with: C extends > AbstractCollection, I have the Class object T specifying what type > of objects C should hold and I have a method M which takes a C<T> > as an argument. I made a generic version of C (without the type) > and now I have to set it so it can only carry objects of type T. > Does anyone know how to do this ? > > Information in programming style: > > C extends AbstractCollection myCollection; > Class itemType; > > > public void myMethod(C<itemType> myCollectionArgument) > > How do I convert myCollection from being a C to a C<itemType> on > runtime so I can call myMethod(myCollection) ? > > I hope the explanation of my problem makes sense and someone can > help me. > > Regards, > > > -- > > - Frank > > _______________________________________________ > freebsd-questions@freebsd.org > <mailto:freebsd-questions@freebsd.org> mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org > <mailto:freebsd-questions-unsubscribe@freebsd.org>" > > Whell just after I posted my mail to this list I realized that I may have fogotten to mention something: I want to do the 'conversion' because the myCollection Collection is still empty. So in other words I want to create a new collection and fill it. However I do not know the type of the items I want to put in beforehand so it has to occur dynamically. So an equivalent question may be: How do I create a new 'C extends AbstractCollection<itemType>' using reflection ? -- - Frank
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?495534BC.1020209>