前提
(例)
TypeScriptで●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
実現したいこと
Listに格納したクラスを取得したい
発生している問題・エラーメッセージ
Main.java:53: error: illegal start of expression
BreadClass breadItem = <BreadClass>breadList.get(0);
該当のソースコード
public class Main {
public static void main(String[] args) {
//Input情報取得
Scanner sc = new Scanner(System.in);
//商品情報を取得 //1行目:パンの種類数、クエリ数 int typeCnt = sc.nextInt(); int qeryCtn = sc.nextInt(); //パン情報をリストに格納 //Input:金額・個数 List<BreadClass> breadList = new ArrayList<>(); for (int i = 0; i < typeCnt; i++) { BreadClass breadItem = new BreadClass(); //breadItem.setTypeCode(i+1); breadItem.setUnitPrice(Long.parseLong(sc.next())); breadItem.setQuantity(sc.nextInt()); breadList.add(breadItem); } //クエリの沿って処理実行 //Input:クエリ・商品(N) for (int i = 0; i < qeryCtn; i++) { String[] line = sc.nextLine().split(" ");; switch(line[0]){ case "buy": BreadBuy(line, breadList); break; } } } /* パン購入処理 */ public static void BreadBuy (String[] line, List breadList){ Long total = 0L; int size = line.length; System.out.println(size); for (int i = 0; i < size-1; i++) { //購入数を取得 int test = Integer.parseInt(line[i+1]); //パン情報を取得 BreadClass breadItem = new BreadClass(); //ここでエラー BreadClass breadItem = <BreadClass>breadList.get(0); } }
}
/*
パンオブジェクト
*/
class BreadClass {
//単価 Long unitPrice = 0L; public Long getUnitPrice(){ return this.unitPrice; } public void setUnitPrice(Long unitPrice){ this.unitPrice = unitPrice; } //数量 int quantity = 0; public int getQuantity(){ return this.quantity; } public void setQuantity(int quantity){ this.quantity = quantity; }
}