path | title |
---|---|
/learnings/java |
Learnings: Java |
- Dev Environment Tools >
- Iteration >
- Instance Initializers / Initializer Blocks >
- (Faking) Initialization Blocks when creating instances of Object
- New in Java 9
- Oracle 1Z0-808 Course Prep >
- Casting
- Development Environment in Docker : >
- See also:
- Book Recommendations
function packagePathToFolderPath() {
mkdir -p $1/main/java
cd $1/main/java
mkdir -p $(echo $2 | sed -e 's/\./\//g')
}
$ packagePathToFolderPath $PROJECT_DIR/src com.wilcoxd.myapp.things
String[] things = ["One", "Two", "three"]
for ( String currentThing : things) {
}
Works over anything that implements Iterable
Called at the time the instance's variable initializers are evaluated (after superclass construction, before constructor body).
HashMap<String, String> h = new HashMap<String, String>(){
h.put("key", "value");
}
class Thing {
String myName;
{
myName = "Yo";
}
}
class Thing {
static String myName;
static {
myName = "Hello world";
}
}
Have to use this instead of constructors, because don't have constructors (no names!)
Example:
public void main(String[] args) {
HashMap<String, String> a = new HashMap<String, String>() {
{
put("key", "value");
}
};
}
Technically is creating an anon class derived from specified class (outer braces) AND THEN using an initializer block
See also:
- http://wiki.c2.com/?DoubleBraceInitialization
- https://stackoverflow.com/a/31829153/224334 <-- explains what I said above
- https://stackoverflow.com/a/27521360/224334 <-- why this might be a bad idea (class explosion in your classloader, potential memory leaks)
##@Depreciated <-- has problem: when? Or is there just s better way?
New attributes:
- ForRemoval <---- it' going away
- since <--- when it's considered old
Warnings can be set to warn on since, etc etc
Stream.ofNullable(objOrMaybeNullWhoKnows) <--- makes a stream of the object, or maybe an empty stream because the object might be null
Integer myThing = ( Integer )( param );
Integer myThing = Integer::cast( param );
CMD /usr/share/maven/bin/mvnDebug exec:java
<-- this exposes a port and you can point a debugger to this image host
Debugging Java in a Container via IntelliJ
- Learning_Ops_Java_Docker
- Learning_Ops_SRE_Java