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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.