【问题标题】:java attempting to assign weaker access privilege errorjava试图分配较弱的访问权限错误
【发布时间】:2012-07-23 07:04:47
【问题描述】:
[javac] U:\dms-webui-testing\test-java\dmswebui\CR\TestLogin.java:16: until() in  cannot override until() in com.thoughtworks.selenium.Wait; attempting to assign weaker access privileges; was public

我得到了一个相当简单的代码的错误:

package dmswebui.CR;

import org.infineta.webui.selenium4j.MainTestCase;

public class TestLogin extends MainTestCase {

  @Override
  public void setUp() throws Exception {
    super.setUp();
    startSeleniumSession("ChromeDriver", "somesite");
  }

  public void testMethod() throws Exception {

        new Wait("") {boolean until() {return false;}};session().open("/");
        new Wait("") {boolean until() {return false;}};session().click("id=btnLogin-button");       session().waitForPageToLoad("30000");
        for (int second = 0;; second++) {
            if (second >= 60) fail("timeout 'waitForTextPresent:Logoff' ");
            try { if (session().isTextPresent("Logoff")) break; } catch (Exception e) {}
            Thread.sleep(1000);
        }
        new Wait("") {boolean until() {return false;}};session().click("id=btnUserLogout-button");
        new Wait("") {boolean until() {return false;}};session().click("id=yui-gen0-button");       session().waitForPageToLoad("30000");
  }
  public void tearDown() throws Exception {
    super.tearDown();
    closeSeleniumSession();
  }


}

here 是我使用 Wait 类的方式。请帮助我理解这个错误。

【问题讨论】:

  • 看起来他们在自己的 javadoc 中提供了错误的示例;)

标签: java compiler-errors selenium-rc


【解决方案1】:

有问题的行是下面两行

new Wait("") {boolean until() {return false;}};session().open("/");
new Wait("") {boolean until() {return false;}};session().click("id=btnLogin-button");

您尝试通过仅包可见的until 方法覆盖在com.thoughtworks.selenium.Wait 类中具有public 访问权限的until 方法。

您不能覆盖方法并降低可见性。您只能增加可见性(例如,覆盖 protected 方法并使其变为 public

因此解决方法是在这些方法中添加 public 关键字

new Wait("") {public boolean until() {return false;}};session().open("/");
new Wait("") {public boolean until() {return false;}};session().click("id=btnLogin-button");

【讨论】:

  • 比 Keppil 早了一秒。谢谢你们俩。 :)
  • 是的,你的意思是我只能提高知名度。覆盖受保护的方法并将其公开,但不包。我认为包修饰符可以增加受保护的可见性,我的理解是否正确?
  • @Richard 不,这是不正确的。受保护的方法对所有子类都是可见的,包外的子类也是如此。因此,使其包可见会增加某些情况下的可见性(同一包中的另一个类),但在其他情况下也会降低可见性(另一个包中的子类)。
  • 简单地说,javac不会编译它,所以它不完全是可见性的扩展。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-22
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 1970-01-01
相关资源
最近更新 更多