java generic addition

前端 未结 4 1077
-上瘾入骨i
-上瘾入骨i 2021-01-25 01:23

I\'m attempting implement the add method mentioned in the Generic sparse matrix addition question

class Matrix
{
  private T add(T left,          


        
4条回答
  •  悲&欢浪女
    2021-01-25 02:08

    The compiler doesn't let you do this because T might be some other class, such as Double.
    You know that T is Integer from the instanceof check, but the compiler doesn't.

提交回复
热议问题