我試圖找出 HH:MM:SS 格式的兩個 LocalTime 物件之間的時間差異,而我的持續時間物件給了我錯誤 Duration.between cannot be resolve to a type。Java 檔案的 between 描述明確表示 LocalTime 物件是有效的——我是否必須將我的物件轉換為具有區域的 LocalDateTime 物件才能使 Duration 作業?
關于這個問題的唯一其他理論是我在我的 Make 檔案中放置這個類,但我認為我的匯入會在編譯期間解決這個問題。下面的代碼:
import java.time.*;
import java.time.Duration;
public class Station {
int stationNumber;
String stationAddress;
ArrayList<Driver> drivers;
ArrayList<Road> roads;
double[][] roadMap;
public Station(int sNumber, String sAddress) {
stationNumber = sNumber;
stationAddress = sAddress;
drivers = new ArrayList<Driver>();
roads = new ArrayList<Road>(5);
roadMap = new double[5][5];
}
public static void calculateNewTimes(ArrayList<roadDataToBeSorted> delDataIncreasingTime) {
LocalTime firstStop = LocalTime.parse(delDataIncreasingTime.get(0).rdDeliveryTime);
LocalTime lastStop = LocalTime.parse(delDataIncreasingTime.get(delDataIncreasingTime.size()-1).rdDeliveryTime);
Duration duration = new Duration.between(firstStop, lastStop); ***<-----ISSUE***
uj5u.com熱心網友回復:
between是Duration類的靜態工廠方法,回傳一個Duration物件。
所以你不需要使用關鍵字創建Duration物件。new
Duration duration = Duration.between(firstStop, lastStop);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/444333.html
