Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

compilation error

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;

class V2Radiator
{
V2Radiator(ArrayList list)
{
for(int x=0;x<5;x++)
list.add(new SimUnit("V2Radiator"));
}
}

class V3Radiator extends V2Radiator
{
V3Radiator(ArrayList list)
{
super(list);
for(int x=0;x<10;x++)
list.add(new SimUnit("V3Radiator"));
}
}

class RetentionBot
{
RetentionBot(ArrayList list)
{
list.add(new SimUnit("Retention"));
}
}

public class TestLifeSupportSim
{
public static void main(String[] args)
{
ArrayList aList = new ArrayList();
V2Radiator v2 = new V2Radiator(aList);
V3Radiator v3 = new V3Radiator(aList);
for(int z=0; z<20 ; z++)
{
RetentionBot ret = new RetentionBot(aList);
}
}
}

class SimUnit
{
String botType;

SimUnit(String type)
{
botType=type;
System.out.println(type);
}

int powerUse()
{
if("Retetention".equals(botType))
{
return 2;
}
else
{
return 4;
}
}
}

whenever i try to compile this, some type of compilation error comes.it tells

"Note: TestLifeSupportSim.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details. "

what does it mean by that?
 
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not an error; it's a warning that your code might not be type-safe. I haven't got the time to look up the details, but you will probably find something useful in the Java Tutorials: try this section.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks like you dont have type parameters for Arraylist, it will lead to a warning in java 5
 
Sheriff
Posts: 22508
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mehar,

Please read your private messages regarding an important announcement.

Thank you,

Rob
 
Rajat Sarkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mehar Simhadri wrote:looks like you dont have type parameters for Arraylist, it will lead to a warning in java 5



in that case , ArrayList list =new ArrayList(); & ArrayList<Object> list = new ArrayList<Object>(); is both statement works same.
 
Rob Spoor
Sheriff
Posts: 22508
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList<SimUnit> seems to be a better match. That way you won't have to cast the contents when you retrieve them.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic