关于两行java代码

关于两行java代码,java,Java,我正在尝试学习一个基于java的程序,但我对java还是相当陌生的。我对以下两行java代码感到非常困惑。我想我的困惑来自于“类”和“演员”的概念,但只是不知道如何分析 为了这个 XValidatingObjectCorpus<Classified<CharSequence>> corpus = new XValidatingObjectCorpus<Classified<CharSequence>>(numFolds); 如何理

我正在尝试学习一个基于java的程序,但我对java还是相当陌生的。我对以下两行java代码感到非常困惑。我想我的困惑来自于“类”和“演员”的概念,但只是不知道如何分析

为了这个

XValidatingObjectCorpus<Classified<CharSequence>> corpus
        = new XValidatingObjectCorpus<Classified<CharSequence>>(numFolds);
如何理解LogisticRegressionClassifier.train的右侧?LogisticRegressionClassifier.train和LogisticRegressionClassifier之间的区别是什么 ?

是泛型参数。 LogisticRegressionClassifier是泛型类型。 LogisticRegressionClassifier.train是一种通用方法。 这些被称为。它们告诉Java使用内部对象的类型生成外部类的实例——XValidatingObjectCorpus或LogisticRegressionClassifier

通常,它们用于列表和数组,例如或

XValidatingObject语料库和语料库之间的关系是什么? 语料库只是您使用该语句生成的新XValidatingObject语料库对象的名称,因此=new。。。部分

LogisticRetressionClassifier.train是什么意思? 我真的不知道。我建议,我认为这是正确的课程

LogisticRegressionClassifier.train和LogisticRegressionClassifier之间的区别是什么? 你真的无法比较这两者。=左边的一个是对象标识符,右边的一个是分配器,可能是错误的词,但它就是这样做的

两者一起定义了LogisticRegressionClassifier的一个实例,即创建该类型的对象,将其称为classifier,然后为其提供train方法返回的值。同样,请查看API以进一步了解它


顺便说一下,这些看起来像是学习Java的糟糕例子。从简单的代码开始,或者至少从代码中更简单的部分开始。看起来有人用长名字玩得太开心了,API甚至有更长的名字。说真的,我只是完全理解了这一点,Java曾是我的主要语言,但当你尝试做一些简单的事情时,它会变得非常混乱。无论如何,祝你好运

这使得它更加混乱,因为它们不是类的真正方法。而且,它只是说明了什么是泛型,并没有真正回答眼前的问题。你错过了上一节课中的句号。分类器是一个实例,而不是一个类型。
public class Sample<T> { // T implies Generic implementation, T can be substituted with any object. 

    static <T> Sample<T> train(int par1, int par2, int par3){
        return new Sample<T>(); // you are calling the Generic method to return Sample object which works with a particular type of generic object, may it be an Integer or a CharSequence. --> see the main method.

    }

    public static void main(String ... a)
    {
        int par1 = 0, par2 = 0, par3 = 1;
// Here you are returning Sample object which works with a sequence of characters.
        Sample<CharSequence> sample = Sample.<CharSequence>train(par1, par2, par3);
// Here you are returning Sample object which works with Integer values.
        Sample<CharSequence> sample1 = Sample.<Integer>train(par1, par2, par3);


    }

}
public class Sample<T> { // T implies Generic implementation, T can be substituted with any object. 

    static <T> Sample<T> train(int par1, int par2, int par3){
        return new Sample<T>(); // you are calling the Generic method to return Sample object which works with a particular type of generic object, may it be an Integer or a CharSequence. --> see the main method.

    }

    public static void main(String ... a)
    {
        int par1 = 0, par2 = 0, par3 = 1;
// Here you are returning Sample object which works with a sequence of characters.
        Sample<CharSequence> sample = Sample.<CharSequence>train(par1, par2, par3);
// Here you are returning Sample object which works with Integer values.
        Sample<CharSequence> sample1 = Sample.<Integer>train(par1, par2, par3);


    }

}