Why is it not possible to make Java or C++ typeless ?
int, float, double etc any type could inherit from a basetype, but why is this not
possible or not applied ?
I could imagine a Java-“typeless” function like this
void some(BASETYPE anyobject, BASENUMERIC a_number) {
for (int i = 0; i < int(a_number); i ++) {
anyobject.doStuff(i);
}
}
where int inherits from BASENUMERIC.
Edit
Sorry for the confusion. What a mean is not a real typelessness, but if any type inherits from a base type, polymorphism allows me to make a function be callable with any object, but at the same time I was able to
define a specific type.
void any(BASETYPE of_any_type, float a_must_be_float) {
...
Hopefully you can understand my intention better now.
Mostly because type-safety is a good thing. It prevents you from calling floating-point functions with characters. It’s not a problem; it’s a feature which prevents you from shooting yourself in the foot.