0

当我尝试使用 maven 编译代码时,出现以下错误:

constructor TripGuesser in class TripGuesser cannot be applied to given types

但在 Eclipse(实际上是 FuseIDE)中它不会引发错误!

我的代码是这样的:

public class TripGuesser {
   private ArrayList<VehicleAbstract> vehicles;
   private DataAccessHandler dataAcces;
   private String stop_id;

   @SuppressWarnings("unchecked")
   public TripGuesser(ArrayList<? extends VehicleAbstract> vehicles, DataAccessHandler dataAccess, String stop_id){
          this.vehicles = (ArrayList<VehicleAbstract>) vehicles;
          this.dataAcces = dataAccess;
          this.stop_id = stop_id;
    }
}


public class HelsinkiStopsHandler {
    ...
    ArrayList<Vehicle> vehicles = vehiclesPerRoute.get(routeAndDirectionId);
    TripGuesser guesser = new TripGuesser(vehicles, dataAccess, last_stopId);
    ...
}

public class Vehicle extends VehicleAbstract{
       ...
}

public abstract class VehicleAbstract{
       ...
}

我已经尝试过以不同的方式调用构造函数,所以我的类 HelsinkiStopsHandler 看起来像:

public class HelsinkiStopsHandler  {
    ArrayList<? extends VehicleAbstract> vehicles = vehiclesPerRoute.get(routeAndDirectionId);
    TripGuesser guesser = new TripGuesser(vehicles, dataAccess, last_stopId);
}

但我仍然得到同样的错误。

我知道这里有很多熟悉的问题,但这些答案都不适合我......

Java版本:1.7.0

Fuse IDE 版本:6.0.0

使用 maven 版本编译:3.1.0

4

1 回答 1

0

我找到了一个解决方案......当我的代码如下所示时它可以工作:

 public class TripGuesser {
     private ArrayList<VehicleAbstract> vehicles;
     private DataAccessHandler dataAcces;
     private String stop_id;

     @SuppressWarnings("unchecked")
     public TripGuesser(ArrayList<VehicleAbstract> vehicles, DataAccessHandler dataAccess, String stop_id){
      this.vehicles = vehicles;
      this.dataAcces = dataAccess;
      this.stop_id = stop_id;
     }
 }


 public class HelsinkiStopsHandler {
      ...
      ArrayList<? extends VehicleAbstract> vehicles = vehiclesPerRoute.get(routeAndDirectionId);
      ArrayList<VehicleAbstract> vehiclesAbs = (ArrayList<VehicleAbstract>) vehicles;
      TripGuesser guesser = new TripGuesser(vehiclesAbs, dataAccess, last_stopId);
      ...
 }
于 2013-11-05T08:18:20.550 回答