Loading topic
switch.6 min readMONDAY is MONDAY, and that is all it knows. Real programs often need more. A coin has a value in cents. A planet has a mass. A traffic light color has a wait time.6 min readEnumSet and EnumMap.5 min readx and a y. A person has a name and an age. An order has an ID and a total.5 min readequals, hashCode, and toString for free. But that free constructor accepts any values at all. A Range could start at 10 and end at 2, and a Fraction could have zero on the bottom. This chapter shows5 min readequals, hashCode, and toString for free. A record is still a class, though, so you can add your own code to it. This chapter shows the two kinds of code you will add most often: instance methods and static factory methods.5 min readequals, hashCode, and toString, all from one line of code. That convenience has a price. A record follows strict rules, and the compiler enforces them.6 min readfinal field, and a record has no setter methods. But there is a catch. A record only stops its fields from changing. It does not stop the objects those fields point to fro5 min readswitch check what kind of object it has and pull the data out of it in the same step. This chapter shows you how.5 min read