What do I return if the return type of a method is Void? (Not void!)

前端 未结 6 1112
忘掉有多难
忘掉有多难 2020-12-07 12:12

Due to the use of Generics in Java I ended up in having to implement a function having Void as return type:

public Void doSomething() {
    //..         


        
6条回答
  •  我在风中等你
    2020-12-07 12:25

    If, for obscure reasons, you MUST use this type, then indeed returning null seems to be a sensible option, since I suppose return value will not be used anyway.
    The compiler will force you to return something anyway.
    And this class doesn't seem to have a public constructor so new Void() is not possible.

提交回复
热议问题