0

Hey,
I have a need to define a new type such as int,short etc. I have the class with all the base methods it must perform somewhat equivelant but different from the Integer class, Short class etc. However im not sure whether this is an interface i need to define.

Id like to declare something like :

newtype f = 1; 

in the same way an int is declared, but since i only have a class it means i have to do

newtype f = new newtype(1); 

Can anyone link me or anything to how this is done?

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by sepp2k
0

There is nothing you can do to make newtype f = 1 work. Java doesn't allow implicit conversions for non-primitive types. There's also no way to make arithmetic operators like + etc. work with your newtype class.

Using a user-defined number class will always look different than using primitive numbers in Java - you can't avoid that. That's why code using the BigInteger class is so ugly.

Edited by sepp2k

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.