-
Notifications
You must be signed in to change notification settings - Fork 0
Answer
Rey edited this page Mar 3, 2025
·
1 revision
-
Object
@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (obj instanceof Person) { return ((Person) obj).getId().equals(this.getId()); } return false; } @Override public int hashCode() { return Objects.hash(id); }
-
Collection
-
Comparable
@Override public int compareTo(Car o) { // TODO Auto-generated method stub int modelCompare = this.getModel().compareTo(o.getModel()); if (modelCompare != 0) { return modelCompare; } int priceCompare = o.getPrice()- this.getPrice(); if (priceCompare != 0) { return priceCompare; } return this.getSpeed()- o.getSpeed(); }
-
Comparator
PriorityQueue<Car> cars = new PriorityQueue<>((c1, c2) -> { int priceCompare = c2.getPrice() - c1.getPrice(); if (priceCompare != 0) { return priceCompare; } int modelCompare = c2.getModel().compareTo(c1.getModel()); if (modelCompare != 0) { return modelCompare; } return c1.getSpeed() - c2.getSpeed(); });
-
-
Exception
-
checkAgepublic void checkAge(int age) throws Exception { if (age < 18) { throw new InvalidAgeException("나이는 18세 이상이어야 합니다."); } System.out.println("나이 검증 통과!"); }
-
checkAgeResultpublic void checkAgeResult(int age) { try { checkAge(age); } catch (Exception e) { // Code } }
-
unchecked
public void divide(int n) { try { int i = 10 / n; } catch (Exception e) { } }
-
-
File IO
-
Book
public class Book implements Serializable { private String title; private String author; private String isbn; private int price; private transient String ssn; }
-