In Java, you can use the +
operator on numbers such as long, short, int and double
but also their object variants (Long, Short, Integer and Double)
and on Strings
for concatenation.
- On what objects is the
+ operator
also defined? - Can I make my own objects which also use the + operator?
- Are objects that use the
+ operator
all implementations of a certain superclass? This would mean I could create a functionpublic static SuperClass apply(Superclass[] array)
which applies the+ operator
iteratively on the array, so for {1,2,3} this would return 6 and for {"1","2","3"} it would return "123". Is this possible?