Last active
December 16, 2015 00:48
-
-
Save pvorb/5349962 to your computer and use it in GitHub Desktop.
Equivalent to object literals in Java
This file contains 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 ObjLiteralsTest { | |
public void main(String[] args) { | |
Object user = new Object() { | |
int id = 1; | |
String name = "pvorb"; | |
}; | |
// user.id and user.name cannot be accessed, | |
// making the whole construct useless though | |
// | |
// System.out.println(user.id, user.name) | |
// will not compile | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Gist exists to prove that you can create Objects directly in Java. You cannot access it's properties though.