נבנה על ידיBuilt by Ariel Yohimovich
final int[] a אומר שאי אפשר להצביע עם a על מערך אחר.final reference: final int[] a means a can't be pointed at another array.0.17, 56).magic number: A number in the code with no explanation (0.17, 56).final int max = 3;
max = 4;
System.out.println(max);Main.java:4: error: cannot assign a value to final variable max
cannot assign a value to final variable max: max כבר קיבל 3.cannot assign a value to final variable max: max already got 3.MIN_RATING ו-MAX_RATING הם קבועים של המחלקה.MIN_RATING and MAX_RATING are class constants.count הוא מונה static אחד, ו-id הוא שדה final של כל ספר, שנקבע פעם אחת בבנאי.count is one static counter, and id is a final field of each book, set once in the constructor.Book.count ב-static, ו-id בתוך כל עצם.In memory: Book.count under static, and id inside each object.MIN_RATING ו-MAX_RATING הם קבועים של המחלקה. count הוא מונה static אחד, ו-id הוא שדה final של כל ספר, שנקבע פעם אחת בבנאי. בזיכרון: Book.count ב-static, ו-id בתוך כל עצם.MIN_RATING and MAX_RATING are class constants. count is one static counter, and id is a final field of each book, set once in the constructor. In memory: Book.count under static, and id inside each object.final int[] scores נועל את החץ, לא את המערך: scores[0] = 95 מותר, אבל scores = new int[3] היה נעצר בקומפילציה.final int[] scores locks the arrow, not the array: scores[0] = 95 is allowed, but scores = new int[3] would be stopped at compile time.final int[] scores נועל את החץ, לא את המערך: scores[0] = 95 מותר, אבל scores = new int[3] היה נעצר בקומפילציה.final int[] scores locks the arrow, not the array: scores[0] = 95 is allowed, but scores = new int[3] would be stopped at compile time.cannot assign a value to final variable count:cannot assign a value to final variable count:final int count = 0;
for (int i = 1; i <= 10; i++) {
if (i % 3 == 0) {
count++;
}
}
System.out.println(count);Main.java:6: error: cannot assign a value to final variable count
cannot assign a value to final variable count: מונה חייב להשתנות, ולכן הוא לא יכול להיות final.cannot assign a value to final variable count: a counter must change, so it can't be final.Book יש MIN_RATING ו-MAX_RATING, מונה private static int count, ו-private final int id. הבנאי בודק את הדירוג לפני שהוא סופר. צרו את Dune (5), Emma (4) ו-Ulysses (9), כל אחד ב-try משלו, והדפיסו #1 Dune (5), #2 Emma (4), Error: Rating must be 1-5, got 9, Books: 2.Book has MIN_RATING and MAX_RATING, a counter private static int count, and private final int id. The constructor checks the rating before counting. Create Dune (5), Emma (4) and Ulysses (9), each in its own try, and print #1 Dune (5), #2 Emma (4), Error: Rating must be 1-5, got 9, Books: 2.final int[] a אומר שאי אפשר להצביע עם a על מערך אחר.final reference: final int[] a means a can't be pointed at another array.0.17, 56).magic number: A number in the code with no explanation (0.17, 56).MIN_RATING ו-MAX_RATING הם קבועים של המחלקה.MIN_RATING and MAX_RATING are class constants.count הוא מונה static אחד, ו-id הוא שדה final של כל ספר, שנקבע פעם אחת בבנאי.count is one static counter, and id is a final field of each book, set once in the constructor.Book.count ב-static, ו-id בתוך כל עצם.In memory: Book.count under static, and id inside each object.final int[] scores נועל את החץ, לא את המערך: scores[0] = 95 מותר, אבל scores = new int[3] היה נעצר בקומפילציה.final int[] scores locks the arrow, not the array: scores[0] = 95 is allowed, but scores = new int[3] would be stopped at compile time.cannot assign a value to final variable count:cannot assign a value to final variable count:final int[] a = {1, 2}; מה מהבאים יתקמפל?final int[] a = {1, 2}; Which of these compiles?a[0] = 5;a[0] = 5;a = new int[2];a = new int[2];a = null;a = null;a[0] = 5;a[0] = 5;static final int MAX_RATING = 5;static final int MAX_RATING = 5;final int maxRating = 5;final int maxRating = 5;const int MAX = 5;const int MAX = 5;static int MAX = 5;static int MAX = 5;static final int MAX_RATING = 5;static final int MAX_RATING = 5;String היא final class. מה זה אומר?String is a final class. What does that mean?String מזויפת שמתנהגת אחרת.Right: nobody can write a fake String that behaves differently.Grade עם קבועים PASS = 56 ו-MAX = 100, ו-static String result(int score) שמחזירה pass, fail או invalid (מחוץ ל-0 עד MAX).A class Grade with constants PASS = 56 and MAX = 100, and static String result(int score) returning pass, fail or invalid (outside 0 to MAX).Ticket עם private static int nextId = 1, ושדות private final int id ו-private final String owner.A class Ticket with private static int nextId = 1, and fields private final int id and private final String owner.Week עם הקבוע static final String[] DAYS (Sun עד Sat) ו-static String dayName(int day) (1 עד 7, אחרת זורקת day must be 1-7, got 8).A class Week with the constant static final String[] DAYS (Sun to Sat) and static String dayName(int day) (1 to 7, otherwise it throws day must be 1-7, got 8).Book יש MIN_RATING ו-MAX_RATING, מונה private static int count, ו-private final int id.Book has MIN_RATING and MAX_RATING, a counter private static int count, and private final int id.Temperature יש בנאי private, ושתי מתודות יצרן:Temperature has a private constructor and two factory methods:final class TextUtil עם בנאי private ריק (כדי שאיש לא ייצור ממנה עצם), ושתי מתודות static:final class TextUtil with an empty private constructor (so nobody makes an object of it), and two static methods:final int[] a אומר שאי אפשר להצביע עם a על מערך אחר.final reference: final int[] a means a can't be pointed at another array.MIN_RATING ו-MAX_RATING הם קבועים של המחלקה.MIN_RATING and MAX_RATING are class constants.final int[] scores נועל את החץ, לא את המערך: scores[0] = 95 מותר, אבל scores = new int[3] היה נעצר בקומפילציה.final int[] scores locks the arrow, not the array: scores[0] = 95 is allowed, but scores = new int[3] would be stopped at compile time.cannot assign a value to final variable count:cannot assign a value to final variable count:נבנה על ידיBuilt by Ariel Yohimovich