What is the purpose of List?

前端 未结 4 561
清歌不尽
清歌不尽 2021-02-05 01:01

I didn\'t even know this was doable, but I saw while perusing some code online a method with a signature like this:

public List read( ... )
         


        
4条回答
  •  一个人的身影
    2021-02-05 01:23

    I agree, it's odd.

    I can see a use for it if you want to extend a generic class and return void from a method. I've bumped into a case were I want to use int and had to use Integer because java generics don't like primitive types.

    public interface ObjectUserPool {
        public E useObject(T o);
    }
    
    public class NonReturningObjectUserPool extends ObjectUserPool {
        public Void useObject(Integer i);
    }
    

    I think this is what the java API is saying, though to be honest I can't really find a use for NonReturningObjectUserPool.

提交回复
热议问题