理解java xode [英] Understanding a java xode

查看:77
本文介绍了理解java xode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java编程的初学者。我需要了解并使用已编写的程序。该程序尝试创建一个包含节点的模型,并为每个节点分配不同的边。但是我在理解代码的某些部分时遇到了问题。有人可以帮助我理解以下部分的工作原理吗?

  import  java.util.Hashtable; 
import java.util.Enumeration;
import java.util.Vector;
import java.io. *;

public class 模型 implements Serializable {
public String name = NoName;
transient DomainClassLoader classLoader = null;
Hashtable conceptIndex = new Hashtable();
private Hashtable classDescriptors = new Hashtable();
private boolean autoUpdateTransferRule = false;
Hashtable domainClasses = new Hashtable();
public 模型(){
尝试 {
new EClassDescriptor( this this .getClass()) ; // 声明1
new EClassDescriptor( this ,Class.forName( rpr。 CNP)); // 声明2
RClassDescriptor rRCD = new RClassDescriptor( this ,Class.forName( rpr.R));
new RClassDescriptor( this ,Class.forName( rpr.HasInverse));
new RClassDescriptor( this ,Class.forName( rpr.Sbf));
new Sbf(rRCD.getInverseDescriptor(),rRCD);
} catch (CAlreadyExistException e){
e.printStackTrace();
}
catch (ClassNotFoundException e2){
e2.printStackTrace();
}
枚举类= classDescriptors.elements();
while (classes.hasMoreElements())
((ClassDescriptor)classes.nextElement())。initMetaR();
RClassDescriptor r = getRClassDescriptor(R。 class );
autoUpdateTransferRule = true;
}
}





声明1(第17行)或声明2(第18行)如何...工作?

行语句1,语句2,...如何与Hashtable相关?



我试过的:



我搜索了类似的代码,但我找不到很多。

解决方案

< blockquote>你不明白代码的原因有很多:



1.它有一些高级主题 - Class 键入Java。 Java中的类很容易理解,但理解Class或类似的类需要对Reflection的用途有所了解,至少需要一个基本的Java API中的专有技术。

2.班级本身没有显示 - 至少对我们而言。



代码执行的操作非常简单:它正在构建EClassDescriptor类型的新对象,但该对象使用的是当前对象(Model)以及你传递的类型。在第17行,Model的类类型,在下一行中,它是通过给定名称 - rpr包中的Cnp类构造一个新类型。尽管如此,从初学者的角度来看,所有这些概念都非常复杂,所以我建议你重新阅读之前的内容(你找到代码的地方),或者你会得到一本关于这些主题的好书。



要了解更多相关信息,请阅读以下Oracle文档指南,

使用此关键字(Java™教程>学习Java语言>类和对象) [ ^ ]

Class(Java Platform SE 7) [ ^ ]



注意:代码写得很差,创建对象并且不使用它们的句柄。为什么首先创建它们。


I am a beginner in Java programming. I need to understand and use an already written program. The program tries to create a model with nodes and assigns different edges to each node. But I have problems with understanding some parts of the code. can someone help me to understand how the following part works?

import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
import java.io.*;

public class Model implements Serializable{
    public String name = "NoName";
    transient DomainClassLoader classLoader = null;
    Hashtable conceptIndex = new Hashtable();
    private Hashtable classDescriptors = new Hashtable();
    private boolean autoUpdateTransferRule = false;
    Hashtable domainClasses = new Hashtable();
    public Model(){
        try{
            new EClassDescriptor(this, this.getClass());           //statement 1
            new EClassDescriptor(this, Class.forName("rpr.Cnp"));  //statement 2
            RClassDescriptor rRCD = new RClassDescriptor(this, Class.forName("rpr.R"));
            new RClassDescriptor(this, Class.forName("rpr.HasInverse"));
            new RClassDescriptor(this, Class.forName("rpr.Sbf"));
            new Sbf(rRCD.getInverseDescriptor(), rRCD);
        } catch(CAlreadyExistException e) {
            e.printStackTrace();
        }
        catch(ClassNotFoundException e2) { 
            e2.printStackTrace();
        }
        Enumeration classes = classDescriptors.elements();
        while(classes.hasMoreElements())
            ((ClassDescriptor) classes.nextElement()).initMetaR();
        RClassDescriptor r = getRClassDescriptor(R.class);
        autoUpdateTransferRule = true;
    }
}



How does the statement 1(line 17) or statement 2 (line 18)… works?
How does the lines statement 1, statement 2, … are related to the Hashtable?

What I have tried:

I searched for similar codes but I couldn't find a lot.

解决方案

You do not understand the code because of many reasons:

1. It has some advanced topics — Class type in Java. Classes in Java are simpler to understand, but understanding Class or similar ones require a bit of understanding of what Reflection is what is it used for, at least a basic know-how of Reflection in Java API is required.
2. The class itself is not shown — at least to us.

What that code is doing is pretty much simple: It is constructing a new object of type EClassDescriptor, but that object then is using current object (Model) as well as the type that you are passing. In line 17, the Class type for Model and in the next line it is constructing a new type by the given name — Cnp class in the rpr package. Nonetheless, all of these concepts are pretty much complex from a beginners perspective so I would recommend that you either re-read the previous content (where you found that code), or you get a good book on these topics.

To understand more on this, please read the following guides on Oracle docs,
Using the this Keyword (The Java™ Tutorials > Learning the Java Language > Classes and Objects)[^]
Class (Java Platform SE 7 )[^]

Note: Also the code is written poorly, objects are created and no handle to them is used. Why created them in first place then.


这篇关于理解java xode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆