programming:java:java
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| programming:java:java [2023/11/02 14:19] – [Tokenize strings] skipidar | programming:java:java [2023/11/02 14:33] (current) – [Records] skipidar | ||
|---|---|---|---|
| Line 1180: | Line 1180: | ||
| } | } | ||
| - | | + | </ |
| + | |||
| + | |||
| + | ===== Records ===== | ||
| + | First: Java 14 | ||
| + | |||
| + | |||
| + | |||
| + | <sxh java> | ||
| + | // some interface | ||
| + | interface MyBarkInterface{ | ||
| + | default void bark(){ | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | record MyPoint(int x, int y) implements MyBarkInterface{}; | ||
| + | |||
| + | // Cant inherit from Record - its final | ||
| + | //record MyPoint2(int x, int y) extends MyPoint{}; | ||
| + | |||
| + | |||
| + | @Test | ||
| + | void recordTest1() { | ||
| + | MyPoint p = new MyPoint(1, | ||
| + | |||
| + | System.out.println(p); | ||
| + | System.out.println(p.x()); | ||
| + | System.out.println(p.x()); | ||
| + | |||
| + | p.bark(); // can access hiearchy | ||
| + | } | ||
| </ | </ | ||
programming/java/java.1698934784.txt.gz · Last modified: by skipidar
