java - Why I can't use + operator with Integer and Double in generic method? -


i encountered strange issue. don't understand why code doesn't work:

public static <type1 extends  integer, type2 extends double >                 object addition(type1 first, type2 second)      {          return second * first;      } 

the compiler claims operator * cannot applied type2,type1. types extends integer , double has + operator defined them. don't understand this

you wrong. neither integer nor double or other objects extending number class have "+" or other operator definied. reason why able perform (integer + double) autoboxing. , autoboxing kind of "hardcoded" feature applies small predefined set of classes, such integer, double, etc.

furthermore, integer , other number subclasses declared "final", therefore "type extends integer" has no meaning, since cannot extend integer.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -