Java 引用不正确

标签 java methods reference

我正在使用 OWL-S API(此处的源代码和 javadoc: http://on.cs.unibas.ch/owls-api/apidocs/ )

如果我这样做,我会得到正确的结果:

public class Example {
    private static ISWRLFactory factory; //is a interface
    private string url = "http://...";
    private Service aService;
    private OWLOntology ont;

    void method_A(){
            URI aURI = URI.create(url);
            OWLKnowledgeBase aKB = OWLFactory.createKB();    
            aService = aKB.readService(aURI);
            ont = aKB.createOntology(aURI);
            ont.createService(aService.getURI());

    }

    void method_B(){
    factory = SWRLFactory.createFactory(ont);
    Atom builtAtom = factory.createNotEqual(x, variab); //x and variab are two variable
    }
   }

但是如果我这样做,我不会得到正确的结果:

public class Example {
    private static ISWRLFactory factory; //is a interface
    private string url = "http://...";
    private Service aService;
    private OWLOntology ont;


    void method_A(){
            URI aURI = URI.create(url);
            OWLKnowledgeBase aKB = OWLFactory.createKB();    
            aService = aKB.readService(aURI);
            ont = aKB.createOntology(aURI);
            ont.createService(aService.getURI());
            factory = SWRLFactory.createFactory(ont);
    }

    void method_B(){
    Atom builtAtom = factory.createNotEqual(x, variab); //x and variab are two variable
    }
}

为什么?

最佳答案

执行“factory = SWRLFactory.createFactory(ont);”时存在差异method_A() 和 method_B() 中的行。 您确定“工厂”对象在 method_A() 和 method_B() 调用之间没有被修改吗? “x”和“变量”对“工厂”有一定的依赖性吗?

关于Java 引用不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20225269/

相关文章:

c++ - C++ 中的 vector 指针和通过引用传递对象

PHP/MongoDB : how does references work in php?

c++ - 如何修复此 C++ 全局对象指针 hack?

java - 我们如何从可编辑的Java代码生成IntelliJ IDEA中的序列图?

java - Hibernate 验证错误的实体外键

java - 使用不带数组的 toString 方法?

Java读入时带空格

java - 错误代码 : Why is this dangerous?

java - Spring Batch 提交间隔不起作用并且工作行为很奇怪

java - 检查字符是否等于单词