Issue
I am having an issue in using a class in a multi module project:
I have a multi module project with a util modules like this: HighLevelProject -> CoreProject -> UtilProject
In UtilProject I have this code :
public interface UrlFactory
{
URL getUrl(String url) throws Exception;
HttpClient getClient();
}
In CoreProject I have this code with the dependency to the UtilProject:
import com.utilProject.UrlFactory;
public class RespUrlFactory implements UrlFactory {
public static UrlFactory resp = null;
@Override
public URL getUrl(String url) throws Exception {
return resp(url);
}
@Override
public HttpClient getClient() {
return resp();
}
And in the HighLevelProject I have this code:
import com.coreProject.RespLinkFactory;
import com.utilProject.UrlFactory;
public static void setLinkFactory() {
RespUrlFactory.resp = new UrlFactory() {
@Override
public URL getUrl(String url) throws Exception {
return new URL(url);
}
@Override
public HttpClient getClient() {
return resp();
}}
At this "HighLevelProject" on this line "RespUrlFactory.resp = new UrlFactory()" I have the next error when building the project:
error: incompatible types: <anonymous com.utilProject.UrlFactory> cannot be converted to com.coreProject.UrlFactory
RespUrlFactory.resp = new UrlFactory() {
Do you have any idea what am I doing wrong?
Solution
It appears that you are defining two different UrlFactory interfaces, one in com.utilProject and one in com.coreProject. I'm getting this directly from the error message:
incompatible types: <anonymous com.utilProject.UrlFactory> cannot be converted to com.coreProject.UrlFactory RespUrlFactory.resp = new UrlFactory() {
Where is com.coreProject.UrlFactory defined? The Java compiler is saying that it exists, so it must be defined somewhere. That's the core (no pun intended) problem here. There may be other issues with this code, but this is the initial mystery to be solved.
Did you maybe mean to move the definition of UrlFactory from one package to another, but instead copied it? OR, could this be a build problem? Might there be a stale .class file lying around or something like that. Was UrlFactory ever in the com.coreProject package?
UPDATE: For yucks, why don't you try renaming the UrlFactory interface that you can see. I'm curious if the names of both types will change, or just the one in com.utilProject. This will tell you something either way.
Answered By - CryptoFool
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.