σʔλܕ numbers • int int x = 1; int hex = 0xDEADBEEF; • double double y = 1.1; double exponents = 1.42e5; int x = 4 / 2; // error int y = 5 ~/ 2; // y = 2 • num: int or double num z = 4 / 2; // z = 2.0 (double) z = 2; // z = 2 (int), no error
มɾఆ var num1 = 1; final num3; const num4 = 4; int num2 = 2; final int num5; const int num6 = 6; • var ͘͠໌ࣔతʹܕΛ༩͑ͯఆٛ͢Δɻ • constͱfinalͲͪΒఆΛఆٛ͢Δ͕ɺ constίϯύΠ ϧ࣌ʹ͕ඞཁͰɺfinalίϯύΠϧ࣌ʹෆཁ͕ͩҰ Λ༩͑ΔͱҎ߱มߋෆՄɻ • _num0ͷΑ͏ʹΞϯμʔείΞΛ͚Δͱprivateͷѻ͍ʹͳ Δʢϝιουಉ͡ʣɻ
try on try { var list = [1, 2, 3]; print(list[3]); } on IndexError { print("Index out of bounds :("); } • catchΛ͚ͭͯྫ֎༰ΛऔΔ͜ͱՄɻ try { var list = [1, 2, 3]; print(list[3]); } on IndexError catch (e) { print("Index out of bounds: $e"); }
try catch try { somethingGoesWrong(); } on ExceptionA { // do something here } on ExceptionB { // do something here } catch (e) { // do something here } • Catch-allͰͯ͢ิ͢Δɻ
Ϋϥε class Cat { final String breed; final int age; final String name; Cat(this.breed, this.age, this.name); } • Cat(this.breed, this.age, this.name) ͷΑ͏ʹthis.ύϥϝʔ λ໊ͱ͢Δ͜ͱͰίϯετϥΫλͷೖॲཧͷهड़Λল ུͰ͖ɺfinalΛ͏͜ͱͰ͖Δɻ
Ϋϥε Factory Constructor class Series { final int id; final String title; final String url; Series(this.id, this.title, this.url); factory Series.fromJson(Map json) { return new Series(json['id'], json['title'], json['url']); } } • ໊લ͖ίϯετϥΫλʹࣅ͍ͯΔ͕ɺதͰΠϯελϯε Λ࡞ͬͯฦ͢ඞཁ͕͋Δɻ