Last active
          March 28, 2019 04:11 
        
      - 
      
- 
        Save jsanders/7f9ce430a294f6d6fb90b302ff348ff3 to your computer and use it in GitHub Desktop. 
    Java data class / record
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public class PointDist { | |
| public static void main(String[] args) { | |
| var point = new Point(3, 4); | |
| System.out.println(String.format("x: %d - y: %d - distance: %f", point.x(), point.y(), point.dist())); | |
| } | |
| static record Point(int x, int y) { | |
| double dist() { | |
| return Math.sqrt(x * x + y * y); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Aaaand it works: