0

Have a question about this kind of syntax.. I will appreciate if anybody can explain me the syntax and the logic of what is going on with the calling of methods after methods and how do i get the access to some class and his methods after the "." ?

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));
Maks.Burkov
  • 358
  • 1
  • 5
  • 19

1 Answers1

0

That is called method chaining.

All it does is, instead of saving the return value of a called method in some variable it directly calls new methods on those returned values.

Example: The following 2 code snippets are doing the same thing,only difference is that we use chaining in 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);
OH GOD SPIDERS
  • 2,399
  • 2
  • 11
  • 15