inheritance - Why don't Java's number classes extend each other? -


in java, why don't built-in number classes extend each other? shouldn't long extend integer extends short extends byte, , double extend float?

in general, inheritance used when there's "is a" relationship. every integer long? think so.

the possible explanation can think of overflow won't handled correctly. example, (byte)100 + (byte)100 -112, whereas (short)100 + (short)100 200. however, seems there should better reason preserving buggy behavior.

you question can approached in 2 different ways:

if talking primitives, have relationship backwards.

but, if asking integer, double, long, etc. classes, there relationship between numbers.

it's important point out numbers objects in java stem common number class found here. doesn't make sense break them down in hierarchy how described because methods between numbers same, despite varying sizes in memory take up.

in short, hierarchies in java defined relationships (typically methods) classes share, not size take in memory.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -