Can I overload an interface in Java?

elm race :

I want to define an interface with same name as other one, but different parameters. How can I do it? Please help.

public interface IFactory<T> {
    IFactory<T> Select(List<String> fields);
    IFactory<T> GroupBy(Expression<?> fields);
    IFactory<T> Where(Object column, ConditionalMethods conditionalMethod, Object... value);
    IFactory<T> And(Object column, ConditionalMethods conditionalMethod, Object... value);
    IFactory<T> Or(Object column, ConditionalMethods conditionalMethod, Object... value);

    T Take();
    T TakeNewObject();
    T TakeAndLock();
}

public interface IFactory<T, Z> {
    IFactory<T, Z> Select(List<String> fields);
    IFactory<T, Z> GroupBy(Expression<?> fields);
    IFactory<T, Z> Where(Object column, ConditionalMethods conditionalMethod, Object... value);
    IFactory<T, Z> And(Object column, ConditionalMethods conditionalMethod, Object... value);
    IFactory<T, Z> Or(Object column, ConditionalMethods conditionalMethod, Object... value);

    T Take();
    T TakeNewObject();
    T TakeAndLock();
}

I get following error:

java duplicate class: com.xxx.IFactory

Eran :

You can't. You must use different names. That's how it is done in JDK interfaces.

For example, consider java.util.function.Function<T, R> vs. java.util.function.BiFunction<T, U, R>. Both are functional interfaces that represent a function, but the first represents a function with one argument (and a result) and the second represents a function with two arguments (and a result).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=78161&siteId=1