import io.cucumber.junit.CucumberOptions;import io.cucumber.junit.Cucumber;import io.cucumber.testng.AbstractTestNGCucumberTests;import org.junit.runner.RunWith;您正在混合 JUnit 和 TestNG。您應該在單個類中使用 JUnit 或 TestNG。不是都。我有一個家長班。我創建了一個包含 3 個父對象的數組。我也有一個兒童班。我是否可以將這 3 個數組元素中的 1 個作為子對象?private ParentClass[] a = new ParentClass[3]ParentClass a[] = { new ParentClass("0"), new ParentClass("1"), new ChildClass("2")};這很好用。但我想知道,這是正確的方法還是有更簡單/更干凈的方法?順便說一句,從 C 到 java 的新手。
1 回答

料青山看我應如是
TA貢獻1772條經驗 獲得超8個贊
或者,您可以執行以下操作,List.of 隨 Java 9 一起提供。返回的列表是不可變的,不可變對象在很多情況下非常好。同樣在Java中,我們也這樣做Interface instance = new ImplementationClass(),例如List<Class> = new ArrayList<>(),ArrayList實現了List接口
List<ParentClass> list = List.of(
new ParentClass("0"),
new ParentClass("1"),
new ChildClass("2")
);
添加回答
舉報
0/150
提交
取消