小编A-m*_*moc的帖子

java:ArrayList预期的<identifier>

我有一个名为Storage的类.存储包含一个名为Products的特殊对象的arraylist.每个产品都包含名称,价格等信息.我的代码如下:

class Storage{

 Product sprite = new Product("sprite",1.25,30);
 Product pepsi = new Product("pepsi",1.85,45);
 Product orange = new Product("orange",2.25,36);
 Product hershey = new Product("hershey",1.50,33);
 Product brownie = new Product("brownie",2.30,41);
 Product apple = new Product("apple",2.00,15);
 Product crackers = new Product("peanut",3.90,68);
 Product trailmix = new Product("trailmix",1.90,45);
 Product icecream = new Product("icecream",1.65,28);
 Product doughnut = new Product("doughnut",2.75,18);
 Product banana = new Product("banana",1.25,32);
 Product coffee = new Product("coffee",1.30,40);
 Product chips = new Product("chips",1.70,35);

 ArrayList<Product> arl = new ArrayList<Product>();

 //add initial elements to arraylist
 arl.add(sprite);
 arl.add(pepsi); …
Run Code Online (Sandbox Code Playgroud)

java arraylist object identifier

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

arraylist ×1

identifier ×1

java ×1

object ×1