0

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 function public 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?
Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
Héctor van den Boorn
  • 1,218
  • 13
  • 32
  • I don't see how this is a duplicate of that other SO thread, but ok... – sstan Jun 26 '15 at 18:43
  • @sstan In my opinion the answer to that other (differently asked) question answers the present one. – Denys Séguret Jun 26 '15 at 18:44
  • 1
    @Denys: not that I'm complaining, but the other thread seems very string specific, and here OP is asking about all objects, and about the possibility of operator overloading, etc. – sstan Jun 26 '15 at 18:50

0 Answers0