如何修复Collection< type>在Eclipse中导入问题 [英] How to fix Collection<type> import issues in Eclipse

查看:56
本文介绍了如何修复Collection< type>在Eclipse中导入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring MVC AOP项目中,除了Model类之外,我还有两个接口和两个类:

In an Spring MVC AOP project I have two interfaces and two classes, beyond a Model class as follows:

  1. ActivityDao(接口)
  2. ActivityDaoImpl(类)
  3. ActivityService(接口)
  4. ActivityServiceImpl(类)
  5. 活动(类)

模型类(n.5):

package com.mycompany.myproject.model;
//... imports
@Entity
public class Activity {
  @NotNull
  private long id;
  private String description;
  public Activity() {
  }
  //... getters and setters
}

Dao界面(n.1):

Dao Interface (n. 1):

package com.mycompany.myproject.dao;
import com.mycompany.myproject.model.Activity;
import java.util.Collection;

public interface ActivityDao {
  public Collection<Activity> findAll();
  public void delete(Activity activity);
  public void create(Activity activity);
  public Activity update(Activity activity);
  }
}

Dao的实施(第2条):

Dao Implementation (n. 2):

package com.mycompany.myproject.dao.impl;

import com.mycompany.myproject.model.Activity;
import com.mycompany.myproject.dao.ActivityDao;
import java.util.Collection;
// ... other imports
@Repository
public class ActivityDaoImpl implements ActivityDao {

  //... Spring autowiring, etc.

  public Collection<Activity> findAll(){ //...
  }
  // other methods implementation
}

服务界面(n.3):

package com.mycompany.myproject.service;
import com.mycompany.myproject.model.Activity;
import java.util.Collection;
//... other imports

public interface ActivityService {
  public Collection<Activity> getAllActivities();
  // other method statements
}

服务等级(n.4):

package com.mycompany.myproject.service.impl;
import com.mycompany.myproject.model.Activity;
import com.mycompany.myproject.dao.ActivityDao;
import java.util.Collection;
import com.mycompany.myproject.service.ActivityService;
// ... other imports
@Service
@Transactional(readOnly = true) 
public class ActivityServiceImpl implements ActivityService {

  @Autowired
  ActivityDao activityDao;      

  public Collection<Activity> getAllActivities(){ //<=== ERROR!
     return activityDao.findAll(); 
  }
  // other methods implementation
}

Eclipse的Java语法检查g在服务类实现(n.4)中具有Collection返回类型的每个方法中都会显示错误,警告该返回类型与Dao的方法return不兼容.

Java grammar checkingg of Eclipse is showin errors in every method with Collection returning type in Service Class implementation (n.4) warning that the return type is incompatible with Dao's method return.

当从快速修复对话框接受建议时,Eclipse将服务的方法类型更改为 Collection< com.mycompany.myproject.service.Activity> ,而不是 Collection< com.mycompany.myproject.model.Activity> ,这是Model类的正确位置(或者合理的话最好是 Collection< Activity> ).

When accepting suggestions from quick-fix dialog, Eclipse change service's method type to Collection<com.mycompany.myproject.service.Activity>, instead of Collection<com.mycompany.myproject.model.Activity>, that is the right place for the Model Class (or even better just Collection<Activity>, as it would be reasonable).

乍一看,Eclipse环境中的Java语法检查器似乎对接口的Collection类型和Dao类的Collection感到困惑,并威胁说它们不是这样的.

At a first glance, it seems that the java grammar cheker in Eclipse environment is confused about the Collection type from interface and Collection from Dao class, threating it as different ones, when they aren't.

关于如何解决这个非常烦人的问题的任何想法,或者我可能做错了什么?非常感谢!

Any idea on how to fix this very annoyng issue, or what I could be doing wrong? Thanks a lot!

推荐答案

我已经解决了该问题.显然,Eclipse与buildpath中另一个项目中的类有些混淆.迫使它通过修复面板建议来更新导入语句,它在构建路径中从相关项目启动了导入语句.然后再次编写正确的import语句似乎会更新编译器链接,并且现在不再显示错误.

I've fixed the issue. Apparently Eclipse was doing some confusion with classes from another project in buildpath. Forcing it to update import statements throung fix pannel suggestions, it lauched the import statements from the related project in build path. Then again writting the right import statements seems to be updated the compiler links and now errors are not being shown anymore.

这篇关于如何修复Collection&lt; type&gt;在Eclipse中导入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆