User Tools

Site Tools


programming:java:java

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:java:java [2023/11/02 14:13] – [Regular Expressions (java.util.regex)] skipidarprogramming:java:java [2023/11/02 14:33] (current) – [Records] skipidar
Line 1170: Line 1170:
 </sxh> </sxh>
  
 +==== ReplaceAll  ====
  
 +<sxh java>
 +    @Test
 +    void stringReplaceAll() {
 +        String s = "bob and alice like to text each other";
 +        String john = s.replaceAll("\\b(bob)\\b", "john");
 +        System.out.println(john);
 +    }
 +
 +</sxh>
 +
 +
 +===== Records =====
 +First: Java 14
 +
 +
 +
 +<sxh java>
 +    // some interface
 +    interface MyBarkInterface{
 +        default void bark(){
 +            System.out.println("bark bark");
 +        }
 +    }
 +
 +    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,2);
 +
 +        System.out.println(p); // MyPoint[x=1, y=2]
 +        System.out.println(p.x()); // can access vars via methods
 +        System.out.println(p.x()); // can access vars via methods
 +        
 +        p.bark(); // can access hiearchy
 +    }
 +
 +</sxh>
programming/java/java.1698934388.txt.gz · Last modified: by skipidar