🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #117

Re: Converting legacy code to use generics

#117
From: John Steel
Date: Fri, 29 Jun 2007 23:36
47 lines
3228 bytes
"Gillmer J. Derge [TeamB]" <spam@gillmerderge.com> wrote in message 
news:4684fd6d@newsgroups.borland.com...

>> As you can see getValues() returns a Collection, so I can't see what the 
>> warning is trying to tell me.
>
> Collection<GameRec> to Collection.  There are a few ways you can get rid 
> of the problem.
>
> 1. Change your getValues method's return type to Collection<GameRec>. This 
> is probably the most type safe solution, but depending on how big your API 
> is, it might just propagate the problem up the tree.  Now anyone that 
> calls your getValues method expecting a Collection is going to get a 
> similar warning.  In other words:
>
>     Collection foo = gameListManager.getValues(); // warning!

Thanks very much for your help, this is very kind of you.
I am in control of all the source, and the api is pretty much limited to 
these 2 classes (at present!).
As expected, when I changed the GameListManagers getValues() to read

    public Collection<GameRec> getValues() {
        return gameListTreeMap.values();
    }

I found it compiled fine but then the original calling line now gives these 
2 errors:
"GameListRenderer.java": cannot find symbol; symbol  : constructor 
ArrayList(java.util.Collection<GameRec>), location: class 
java.util.ArrayList<java.util.Collection> at line 94, column 40
"GameListRenderer.java": internal error; cannot instantiate 
java.util.ArrayList.<init> at java.util.ArrayList<java.util.Collection> to 
() at line 94, column 40

I'm trying to think this through by describing it in English - I think I'm 
asking for an ArrayList of GameRecs, but we know games.getValues() now 
returns the type safe Collection so its almost as if the syntax end up like 
ArrayList<Collection<GameRec>> gameList =...  , but that wouldn't compile at 
all

(the original caller is     ArrayList<Collection> gameList = new ArrayList 
<Collection> (games.getValues()); ).

I too would like a clean build without "hacks".  There are a few others of 
this ilk relating to Comparators, so I'd like to fix those having understood 
this one.
Technical Details
Message-ID: <468597a1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4684e22c@newsgroups.borland.com> <4684fd6d@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,49d96784a5821e34
X-Google-Attributes: gidf74b3,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "John Steel" <john.steel@phonewebcam.com>
From: "John Steel" <john.steel@phonewebcam.com>
Newsgroups: borland.public.jbuilder.java.language
References: <4684e22c@newsgroups.borland.com> <4684fd6d@newsgroups.borland.com>
Subject: Re: Converting legacy code to use generics
Date: Sat, 30 Jun 2007 00:36:54 +0100
Lines: 50
Organization: www.phonewebcam.com
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 80.192.241.252
Message-ID: <468597a1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1183160225 80.192.241.252 (29 Jun 2007 16:37:05 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail