Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 11 Jun 2012 02:06:57 -0500 Date: Mon, 11 Jun 2012 00:06:54 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:13.0) Gecko/20120604 Thunderbird/13.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: unchecked conversion warning. References: <3s7cs7hd18l0ffci55ns0286n4lc4cutlu@4ax.com> <265ea956-a3ed-4e76-8fc9-9ce9728f6b37@googlegroups.com> In-Reply-To: <265ea956-a3ed-4e76-8fc9-9ce9728f6b37@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 46 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.202.8 X-Trace: sv3-KCjfVNGGYUcVLD9Qqnz+lMm2w262Ort3zN+UqBRnjs3GOUDk1gs4m72sR7cFJhI7V7x1NFmoc5Y5VJ8!D5nwOLUuqfWheYliQApztm0BQh9CraIgyVcCIGDc6EOqEmt5FNm7jM3zUoWHDJ/BGxBzpZ4tpm1v!N1/sEKBR0/o1A3Ol5M9ugnRMxTSbHyt9n3XMbYImMPNa X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2798 Xref: csiph.com comp.lang.java.programmer:15203 On 6/10/2012 9:52 PM, Broad Liyn wrote: > 在 2012年5月30日星期三UTC+8下午9时32分43秒,(未知)写道: >> This code compiles with an 'unchecked conversion' warning. >> I have tried various corrections, for example casting like (Vector), but to no >> avail. >> What am I doing wrong?l >> The code is the smallest demo I could make from the original application. >> >> import java.util.Vector; >> public class genericsdemo >> { >> private static Vector vdata = new Vector(); //a Vector of Vectors >> private static Vector vrow = new Vector(); //a row >> >> public static void main(String args[]) { >> vrow.add(null); //two columns in the row >> vrow.add(null); >> >> vdata.add(vrow); //add the row to the Vector of Vectors >> >> Vector vtmp = getrow(); //test >> } >> >> private static Vector getrow() { >> return vdata.elementAt(0); //warning: [unchecked] unchecked conversion >> } >> } >> >> JensJ > 1.vector is no longer being supported. > 2. > As of JDK 7, Vector is not even deprecated. The documentation, http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html, says "If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector." which implies that Vector might be a reasonable choice if thread safety is needed. Personally, I prefer to use ArrayList as base, and wrap using Collections.synchronizedCollection, but that is not mandatory. Patricia