Fwd: Number problems

Brian Goetz brian.goetz at oracle.com
Mon Sep 30 20:20:36 UTC 2019

Received on the -comments list.

The points raised here are quite sensible, and we've been grappling with 
them in a peeking-down-the-road sort of way, but we're not quite ready 
to engage them directly yet.  Yes, the fact that Number is a class, 
rather than an interface causes certain kinds of problems, and we're 
going to have to contend with them somehow.  There are a variety of 
techniques on the table, but exactly how we do so should be addressed in 
the bigger context of what we want the type hierarchy to look like.  So, 
stay tuned.

-------- Forwarded Message --------
Subject: 	Number problems
Date: 	Sun, 29 Sep 2019 11:26:13 +0200
From: 	Anders Peterson <anders at optimatika.se>
To: 	valhalla-spec-comments at openjdk.java.net


A ComplexNumber class that will be efficient to use is a common example 
of what Valhalla will enable.

In order to be able to write math code that is common for any/all 
“numbers” then the various implementations must have something in common 
- like a common interface.

Inline classes cannot extends any other class - they cannot extend 

Can existing final classes that only extend Object be converted to 
inline classes? Even if that will be possible the classes Double, 
Integer, Long… cannot be converted to inline since they extend Number.

I’m the author of a Java math (linear algebra) library, and very 
interested in the capabilities I believe Valhalla will bring. I plan to 
have a Valhalla-enabled version of my library as soon as it’s released, 
and I’m eager to make adaptations already now that will simply future 

Are there any plans to create a new interface that (re)defines 

Then perhaps a second interface, that extends that first one, and 
further declares methods like add/subtract/multiply/divide/… Most (all) 
classes that today extend java.lang.Number should be able to implement 
this interface AND it can be used to create new numerical inline classes 
like ComplexNumber.

In my library today there is such an interface but there are 
difficulties regarding how to interact and coexist with java.lang.Number 
and the various primitive types. Some of these challenges would go away 
if (something like) the interfaces I invented was defined in “Java” itself.


More information about the valhalla-spec-observers mailing list