Files
java-interview-lab/experienced-2-3y/output/01-core-java.txt
T

23 lines
1.0 KiB
Plaintext

== Q1: equals() without hashCode() ==
equal points in HashSet (equals only): size = 2
equal points in HashSet (record): size = 1
== Q2: unboxing null ==
int n = map.get("pencil") -> NullPointerException
useDefault ? maybe : 0 -> NullPointerException (type of ?: is int)
useDefault ? maybe : Integer.valueOf(0) -> null
map.getOrDefault("pencil", 0) -> 0
== Q3: overridable method in a constructor ==
Child.describe sees constantLabel = child, label = null
Child.describe sees constantLabel = child, label = child
== Q4: defensive copy ==
leaky roster after outside changes: [Asha, Ravi, Intruder, Another]
safe roster after outside change: [Asha, Ravi]
safe roster add -> UnsupportedOperationException
== Q5: keep the cause ==
without cause: invalid port configuration | cause = null
with cause: invalid port configuration | cause = java.lang.NumberFormatException: For input string: "80a"
== Q6: sealed interface + pattern switch ==
Card[last4=4242] -> card ending 4242
Upi[vpa=asha@bank] -> UPI asha@bank
Cod[] -> cash on delivery