The simple way to do this would be to reuse someone else's library. There are some leads in this Q&A:
What you are actually trying to do (extend java.lang.Byte
) is both impossible (because the Byte
class is final
) and conceptually wrong. The sets of numbers represented by an unsigned byte and a signed byte are different. Therefore neither is conceptually a subtype of the other. If you model one as a Java subclass of the other, you will end up with type anomalies and runtime value checking to avoid them.
Finally, while this kind of modeling gives you a nice OO program, the downside is that you will take a significant performance hit relative to using primitive types and "tweaking" to deal with signed versus non-signed. You might be interested to know that there is a new API in Java 8 for doing unsigned operations on signed primitive types.
The API consists of new static
methods in the existing wrapper classes.