Java Reference
In-Depth Information
the user, pass it as a reference once it has been boxed. Similar technology already exists in C#;
quoting Microsoft: [ 5 ]
5 To learn about the syntax and usage of structs and the differences between classes and structs,
see http://msdn.microsoft.com/en-us/library/aa288471(v=vs.71).aspx .
Structs may seem similar to classes, but there are important differences that you should be
aware of. First of all, classes are [C#] reference types and structs are value types. By using
structs, you can create objects [sic] that behave like the built-in [primitive] types and enjoy their
benefits as well.
At the time of writing (June 2014) there's a concrete proposal for value types in Java. [ 6 ]
6 John Rose, et al., “State of the Values,” April 2014 Infant Edition,
http://cr.openjdk.java.net/~jrose/values/values-0.html .
Boxing, generics, value types—the interdependency problem
We'd like to have value types in Java, because functional-style programs deal with immutable
values that don't have identity. We'd like to see primitive types as a special case of value types,
but the erasure model of generics, which Java currently has, means that value types can't be
used with generics without boxing. Object (boxed) versions (for example, Integer) of primitive
types (for example, int) continue to be vital for collections and Java generics because of their
erasure model, but now their inheriting Object (and hence reference equality) is seen as a
drawback. Addressing any one of these problems means addressing them all.
16.3. The final word
This topic has explored the new features added by Java 8; these represent perhaps the biggest
evolution step ever taken by Java—the only comparably large evolution step was the
introduction, 10 years previously, of generics in Java 5. In this chapter we also looked at
pressures for further Java evolution. In conclusion, we propose the following statement:
Java 8 is an excellent place to pause but not to stop!
We hope you've enjoyed the adventure that is Java 8, and that we've sparked your interests in
exploring functional programming and in the further evolution of Java.
 
Search WWH ::




Custom Search