2

I need to use two classes with the same name but different namespaces (foo.request.Response and bar.request.Response) in an interface. In classes this can be achieved by using the full name with namespace :

public foo.request.Response method1() { [...]
public bar.request.Response method2() { [...]

But this does not seem to work in Interfaces.

What is the correct way of dealing with this problem ?

Edit 1 Error comes from Eclipse :

foo cannot be resolved to a type

Interface code :

public interface ITestController {
    String method1(foo.request.Response response);
}

I found the issue, it was not coming from the interface it was a simple mess-up in the dependencies. Thanks for your help ;)

3
  • Any specific error you get? Commented Oct 9, 2014 at 12:24
  • Error is displayed by Eclipse and says 'foo cannot be resolved to a type'. It does not understand the full definition of the classe name Commented Oct 9, 2014 at 12:27
  • I updated the Q with the interface code Commented Oct 9, 2014 at 12:33

1 Answer 1

2

It works in interfaces, but care should be taken so that the implementing classes fully qualify the names in the same way.

Note that you can not choose which of the two classes when implement the interface. It's the interface that specifies which of the two classes is to be used when implementing the interface.

The code you've posted in your answer is messed up. If the two first methods belong to a class implementing ITestController then that class must also include an implementation for

public String method1(foo.request.Response response) { ... }
Sign up to request clarification or add additional context in comments.

2 Comments

I know it was just an example. In fact the issue was coming from a problem in the dependencies ... Thanks for your help
Right. So, the answer to your question is indeed, It works in interfaces, but care should be taken so that the implementing classes fully qualify the names in the same way. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.