Java in Java lang.Void?
I am currently using it Net 2.0 and has an interface whose generic type is used to define the return type of a method It's like
interface IExecutor<T> { T Execute() { ... } }
My problem is that some classes that implement this interface don't actually need to return anything
In Java, you can use Java Lang. void to achieve this goal, but after a lot of search, I found that there is no corresponding thing in C # More generally speaking, I haven't found a good way to solve this problem I tried to find out how people did it with representatives, but I didn't find anything - which convinced me that the problem was that I sucked search:)
So what is the best way to solve this problem? What would you do?
thank you!
Solution
You will have to use object and return null, create your own object to represent void, or just create a separate interface that returns void
This is the second idea:
public class Void { public static readonly Instance = null; // You don't even need this line private Void(){} }
As a result, someone cannot create an instance of the class But what do you have to represent it I think it's probably the most elegant way to do what you want
In addition, you may want to seal this class