Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 这叫什么?_Java - Fatal编程技术网

Java 这叫什么?

Java 这叫什么?,java,Java,这个技术(方法调用返回的对象在同一行上进行了另一个方法调用)有名称吗 而不是 ApplicationServerSettings applicationServerSettings = commonAssets.getApplicationServerSettings(); String pAID = applicationServerSettings.getSetting("plivoAuthID"); 另外,当我执行第一个操作时,Eclipse不会提示我导入类ApplicationServ

这个技术(方法调用返回的对象在同一行上进行了另一个方法调用)有名称吗

而不是

ApplicationServerSettings applicationServerSettings = commonAssets.getApplicationServerSettings();
String pAID = applicationServerSettings.getSetting("plivoAuthID");
另外,当我执行第一个操作时,Eclipse不会提示我导入类
ApplicationServerSettings
,但如果我使用第二个代码样式,它会提示我导入

另外,这两种风格仅仅是偏好吗?

这种技术被称为

wiki中的定义:

方法链接,也称为命名参数习惯用法,是一种常见的方法 面向对象中调用多个方法调用的语法 编程语言。每个方法都返回一个对象,允许 在单个语句中链接在一起的调用,而无需 用于存储中间结果的变量。[1]局部变量 声明是语法糖,因为人类有困难
通过深度嵌套的方法调用。[2][3]方法链也称为 由于出现的方法数量增加而导致的火车失事 一个接一个地出现在同一行中,随着更多方法的出现 链接在一起[4],即使中间经常添加换行符 方法

你的第二个问题:

另外,当我执行第一个操作时,Eclipse不会提示我导入类ApplicationServerSettings,但如果我使用第二个代码样式,它会提示我导入

  • 再次从定义中“每个方法返回一个对象,允许调用在单个语句中链接在一起,而不需要变量来存储中间结果。”这就是为什么它不提示您导入类
    ApplicationServerSettings
另一个看起来更简单的示例(除了您要介绍的内容外):

请看一下wiki示例:

class Person {
    private String name;
    private int age;

    // In addition to having the side-effect of setting the attributes in question,
    // the setters return "this" (the current Person object) to allow for further chained method calls.

    public Person setName(String name) {
        this.name = name;
        return this;
    }

    public Person setAge(int age) {
        this.age = age;
        return this;
    }

    public void introduce() {
        System.out.println("Hello, my name is " + name + " and I am " + age + " years old.");
    }

    // Usage:
    public static void main(String[] args) {
        Person person = new Person();
        // Output: Hello, my name is Peter and I am 21 years old.
        person.setName("Peter").setAge(21).introduce();
    }
}
这种技术被称为

wiki中的定义:

方法链接,也称为命名参数习惯用法,是一种常见的方法 面向对象中调用多个方法调用的语法 编程语言。每个方法都返回一个对象,允许 在单个语句中链接在一起的调用,而无需 用于存储中间结果的变量。[1]局部变量 声明是语法糖,因为人类有困难
通过深度嵌套的方法调用。[2][3]方法链也称为 由于出现的方法数量增加而导致的火车失事 一个接一个地出现在同一行中,随着更多方法的出现 链接在一起[4],即使中间经常添加换行符 方法

你的第二个问题:

另外,当我执行第一个操作时,Eclipse不会提示我导入类ApplicationServerSettings,但如果我使用第二个代码样式,它会提示我导入

  • 再次从定义中“每个方法返回一个对象,允许调用在单个语句中链接在一起,而不需要变量来存储中间结果。”这就是为什么它不提示您导入类
    ApplicationServerSettings
另一个看起来更简单的示例(除了您要介绍的内容外):

请看一下wiki示例:

class Person {
    private String name;
    private int age;

    // In addition to having the side-effect of setting the attributes in question,
    // the setters return "this" (the current Person object) to allow for further chained method calls.

    public Person setName(String name) {
        this.name = name;
        return this;
    }

    public Person setAge(int age) {
        this.age = age;
        return this;
    }

    public void introduce() {
        System.out.println("Hello, my name is " + name + " and I am " + age + " years old.");
    }

    // Usage:
    public static void main(String[] args) {
        Person person = new Person();
        // Output: Hello, my name is Peter and I am 21 years old.
        person.setName("Peter").setAge(21).introduce();
    }
}
它通常被称为流利语法

我认为这是风格的问题,没有对错之分

流利的语法更简洁,这有时是一件好事

另一个变体对于源代码级调试更方便。您可以单步执行语句并检查中间结果。

它通常被称为流利语法

我认为这是风格的问题,没有对错之分

流利的语法更简洁,这有时是一件好事


另一个变体对于源代码级调试更方便。您可以单步执行语句并检查中间结果。

对不同的字符串进行不同的调用,例如place
.getSetting(“plivoAuthID”)在另一个字符串上(为了能够理解崩溃报告),对不同的字符串进行不同的调用,例如place
.getSetting(“plivauthid”)
在另一个字符串上(为了能够理解崩溃报告),这不是正确链接的方法,我可以更正!根据你的报价,这确实符合描述。我以前从来没有用过这个短语。我把我的反对票变成了赞成票。“一个方法链也被称为火车失事”——真漂亮!好的,谢谢@rainbolt。我认为该定义与“方法链接”匹配,我本来打算删除我的答案,但我相信这是用户的要求String pAID=commonAssets.getApplicationServerSettings().getSetting(“plivoAuthID”);'对我来说,这就是方法链接。方法链接并不要求所有方法都返回同一个对象,尽管这是短语“方法链接”最常用的用法,但是新的流API的大多数用法都是方法链接,很少返回同一个对象。这不是方法链接,我要纠正!根据你的报价,这确实符合描述。我以前从来没有用过这个短语。我把我的反对票变成了赞成票。“一个方法链也被称为火车失事”——真漂亮!好的,谢谢@rainbolt。我认为该定义与“方法链接”匹配,我本来打算删除我的答案,但我相信这是用户的要求String pAID=commonAssets.getApplicationServerSettings().getSetting(“plivoAuthID”);'对我来说,这就是方法链接。方法链接并不要求所有方法都返回同一个对象,尽管这是短语“方法链接”最常用的用法,但是新的流API的大多数用法都是方法链接,很少返回同一个对象。“Fluent”属于方法链接的一种特殊情况:每次后续调用发生在同一对象上。“Fluent”属于方法链接的一种特殊情况:每次后续调用发生在同一对象上。
class Person {
    private String name;
    private int age;

    // In addition to having the side-effect of setting the attributes in question,
    // the setters return "this" (the current Person object) to allow for further chained method calls.

    public Person setName(String name) {
        this.name = name;
        return this;
    }

    public Person setAge(int age) {
        this.age = age;
        return this;
    }

    public void introduce() {
        System.out.println("Hello, my name is " + name + " and I am " + age + " years old.");
    }

    // Usage:
    public static void main(String[] args) {
        Person person = new Person();
        // Output: Hello, my name is Peter and I am 21 years old.
        person.setName("Peter").setAge(21).introduce();
    }
}