gpt4 book ai didi

java - 构造函数调用必须是具有继承的构造函数中的第一个语句

转载 作者:行者123 更新时间:2023-12-01 18:01:56 25 4
gpt4 key购买 nike

我有我的父抽象 JUnitTest 类:

public abstract class RestWSTest
{

public RestWSTest()
{
}

@Before
public void setUp() throws Exception
{
...
}

@After
public void tearDown() throws Exception
{
...
}
}

然后我想要一个扩展 RestWSTest 的类,如下所示:

public class RestWSCreateGroupTest extends RestWSTest
{

public RestWSCreateGroupTest()
{
super();
}

@Before
public void setUp() throws Exception
{
super(); --> *Constructor call must be the first statement in a constructor*
...
}

@After
public void tearDown() throws Exception
{
super(); --> *Constructor call must be the first statement in a constructor*
...
}

@Test
public void testCreateGroup()
{
...
}
}

为什么我会收到错误消息?我有一个构造函数,我在那里调用 super(),所以我真的不知道该怎么做...

最佳答案

方法public void setUp()不是构造函数。您不能在其中调用 super(); 。我认为你打算 super.setUp();

关于java - 构造函数调用必须是具有继承的构造函数中的第一个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40286621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com