🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Collections.sort(List)

#707
From: Alan Shiers
Date: Thu, 02 Dec 2004 17:31
43 lines
1928 bytes
Hi there,

I'm trying to understand how to fix a warning message from the Java 1.5
compiler that states:

C:\JavaProjects\CardGames\games>javac -Xlint:unchecked *.java
Deck.java:157: warning: [unchecked] unchecked method invocation:
<T>sort(java.ut
il.List<T>) in java.util.Collections is applied to
(java.util.List<games.Card>)
    Collections.sort(deck);

I'm trying to use the Collections.sort() method to sort a List object.  In
my class I initialize the List object like so:

private List<games.Card> deck = null;

public Deck()
{
    Card[] deckOfCards = new Card[52];
    //Load up the deck with all necessary cards
    for(int i = 0; i < deckOfCards.length; i++)
    {
      deckOfCards[i] = new Card(vrank[i%13], srank[i/13]);
      deckOfCards[i].setAlias(aliases[i]);
    }
    deck = Arrays.asList(deckOfCards);
}

Then, later I have a sort method like so:

public void SortByValue()
{
    Collections.sort(deck);  //<<< This generates the warning noted above
}

I don't get it!  When I created the List object I specified the type:
<games.Card>
So what's its problem?

Please advise,

Alan
Technical Details
Message-ID: <41af522d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,2868f4df97a5ed32
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Alan Shiers" <ashiers@hfx.eastlink.ca>
Newsgroups: borland.public.jbuilder.java.language
Subject: Collections.sort(List)
Date: Thu, 2 Dec 2004 13:31:15 -0400
Lines: 45
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 24.222.101.2
Message-ID: <41af522d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102008877 24.222.101.2 (2 Dec 2004 09:34:37 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail