Last active
December 19, 2015 11:38
-
-
Save t-botz/5948761 to your computer and use it in GitHub Desktop.
Java properties & Lambdas
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 Person { | |
//The syntax obj#field, uses the new operator # which represents a direct access to the field (without getter/setter) | |
//Default public getter/setter | |
private String firstName : (); | |
//Explicitly defined getter/setter using lambda, exact equivalent as the default syntax ().By Default visibility is public | |
private String lastName : (()-> this#lastName, (lastName)-> this#lastName = lastName); | |
//Immutable field. When final the syntax takes only one lambdas, the getter. | |
private final int age : (()-> this#lastName); // similar as () | |
//Ability to modify the visibility through method references. (Visibility inference) | |
private int id = 0 :(()-> this#id, this::setId); | |
private void setId(int id) { | |
this.id = id; | |
} | |
/********************** | |
* Need more thinking : | |
**********************/ | |
//Indexed properties (defined in the javabeans spec) | |
private int[] array = new int[2] : ( | |
( index ) -> { this#array[index] }, | |
( index, value ) -> { this#array[index] = value } | |
); | |
//Properties not backed by a field | |
private final void length : (() -> this#array.length); | |
//Properties can be applied to static fields : | |
private static final int DEFAULT_NUMBER_OF_LEGS = 4 : (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment