【问题标题】:Nested retrieve methods [duplicate]嵌套检索方法[重复]
【发布时间】:2016-04-25 10:48:19
【问题描述】:

对这种语法有疑问.. 如果有人能向我解释在方法之后调用方法的语法和逻辑,以及如何在“。”之后访问某些类和他的方法,我将不胜感激。 ?

WebTarget target = client.target("http://localhost:8080/Activities/rest/");
    Response response = target.path("activitiesGenerator/activity").request(MediaType.APPLICATION_JSON).post(Entity.entity(act,MediaType.APPLICATION_JSON));

【问题讨论】:

    标签: java jersey


    【解决方案1】:

    这就是所谓的方法链。

    它所做的只是,它不是将被调用方法的返回值保存在某个变量中,而是直接在这些返回值上调用新方法。

    例子:下面两个代码sn-ps做同样的事情,唯一不同的是我们在test2中使用了链接。

        String test1 = "Test 1";
        test1 = test1.replace("1", "2");
        test1 = test1.toUpperCase();
        System.out.println(test1);
    
        String test2 = "Test 1".replace("1", "2").toUpperCase();
        System.out.println(test2);
    

    【讨论】:

    • 感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 2014-10-30
    • 2021-05-17
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2020-09-04
    • 2012-06-28
    • 1970-01-01
    相关资源
    最近更新 更多