Premium Partner

OCP - 1

Classes, Desing Patterns, Principles, Generics and Collections

Classes, Desing Patterns, Principles, Generics and Collections


Kartei Details

Karten 124
Sprache English
Kategorie Informatik
Stufe Andere
Erstellt / Aktualisiert 31.01.2019 / 08.01.2020
Lizenzierung Keine Angabe
Weblink
https://card2brain.ch/box/20190131_ocp_1
Einbinden
<iframe src="https://card2brain.ch/box/20190131_ocp_1/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>

What is the Result of `null instanceOf X` ?

False, an instanceOf check with null always results in false

When are instanceOf checks executed?

  • For Classes: At Compiletime
  • For Interfaces: At Runtime

What is virtual method invocation?

It basically means that Jva will look at subclasses when finding the right method to call (override)

What's the goal of @override?

It is helpful because the compiler can tell you when you've messd up

What does the equals signature look like?

public boolean equals(Object obj)

What is the equals contract?

  • "Should not change at random"
    • reflexive: x.equals(x) == true
    • symmetric: x.equals(y) == y.equals(x)
    • transitive: x.equals(y) == y.equals(z) == z.equals(x)
    • consistent: x.equals(y) == x.equals(y) (does not change when x and y are not modified)
  • An object an null are not equal
    • x.equals(null) must return false

What is the contract of hashCode?

  • The result must not change -> derive it from members that do not change (eg. an id)
  • The hasCode() can use a subset of equals
    • two equal objects must return the same hashcode
  • the hash code can be a constant, altough it is not efficient

What does the hashCode signature look like?

public int hashCode()