Generic Methods and Type Inferencing in Java

前端 未结 3 578
攒了一身酷
攒了一身酷 2021-02-06 04:41

Given the following not-very-useful code:

package com.something;

import java.util.ArrayList;
import java.util.Collectio         


        
3条回答
  •  梦毁少年i
    2021-02-06 05:22

    I guess you could say it serves as some sort of documentation, so that the user knows that you expect both arguments to be of the same type. Of course, any two objects are of the same type to some degree (they're all Object), so it's a meaningless statement.

    Long story short, it's a useless signature.

    Of course, if plain returned a type T, that'd be a different story.

提交回复
热议问题