Are inline classes still going to be coming to Java? From what I understand, inline classes are like Haskell's newtype, where a type can become boxed to make it distinct from its original type, but the compiler then erases the boxing class so that there's not any additional memory allocations for the boxing type.
While I think value types are a good thing, I would think Java could have reaped many of the benefits aeons ago if the Thread class had included a few fields of various types that functions could use to pass back multiple return values. If e.g. one wants a function that accepts an angle and makes both the sine and cosine available to the caller, that could have been handled easily by specifying that any function may store arbitrary values in the DoubleRet0 and DoubleRead1 fields of the current thread object, and having the sine/cosine function document that it uses those to return the sine and cosine. If the caller is interested in those values, the caller would be expected to copy them to local variables before calling any other function.
Functions' ability to return structures would be limited to those with few enough fields to fit in the indicated fields, but the relative benefits of returning multi-value types versus passing or returning class object references are greatest when the number of values is greater than one, but still relatively small. The more values need to be returned, the smaller the relative downside to passing or returning a class object.
2
u/DetriusXii Sep 15 '20
Are inline classes still going to be coming to Java? From what I understand, inline classes are like Haskell's newtype, where a type can become boxed to make it distinct from its original type, but the compiler then erases the boxing class so that there's not any additional memory allocations for the boxing type.