From owner-freebsd-questions@FreeBSD.ORG Fri Dec 26 19:47:11 2008 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F28E106564A for ; Fri, 26 Dec 2008 19:47:11 +0000 (UTC) (envelope-from frankstaals@gmx.net) Received: from edu-smtp-02.edutel.nl (edu-smtp-02.edutel.nl [88.159.1.222]) by mx1.freebsd.org (Postfix) with ESMTP id 3E5F18FC13 for ; Fri, 26 Dec 2008 19:47:11 +0000 (UTC) (envelope-from frankstaals@gmx.net) Received: from Rena.FStaals.net (unknown [88.159.208.104]) by edu-smtp-02.edutel.nl (Postfix) with ESMTP id 55044121943; Fri, 26 Dec 2008 20:47:09 +0100 (CET) Message-ID: <495534BC.1020209@gmx.net> Date: Fri, 26 Dec 2008 20:47:08 +0100 From: Frank Staals User-Agent: Thunderbird 2.0.0.18 (Macintosh/20081105) MIME-Version: 1.0 To: Vladimir Tsvetkov References: <4954E849.6020000@gmx.net> <666bdb140812261007p21b23e13k48d80e4a454ce49e@mail.gmail.com> In-Reply-To: <666bdb140812261007p21b23e13k48d80e4a454ce49e@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: questions@freebsd.org Subject: Re: Off-topic: Java Reflection/Generics/Collections question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Dec 2008 19:47:11 -0000 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, > but you can cast Coll to Coll. > > 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 > 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 > 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 myCollectionArgument) > > How do I convert myCollection from being a C to a C 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 > mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "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' using reflection ? -- - Frank