{"id":8970,"date":"2012-09-27T18:00:36","date_gmt":"2012-09-27T12:30:36","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8970"},"modified":"2012-09-27T18:01:52","modified_gmt":"2012-09-27T12:31:52","slug":"canonical-annotation","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/canonical-annotation\/","title":{"rendered":"@Canonical annotation"},"content":{"rendered":"<p>@Canonical: It&#8217;s very useful annotation. It provides the combination of features of @ToString (default implementation of toString() method based upon the fields in the class), @EqualsAndHashCode(default implementation of equals() and hashCode() method of the class based upon the fields in the class) and @TupleConstructor (provides the classical constructor with default properties). <\/p>\n<p style=\"padding-bottom: 10px\">\n<p>[groovy]<br \/>\nimport groovy.transform.Canonical<\/p>\n<p>@Canonical<br \/>\nclass Person {<br \/>\nString name<br \/>\nString address<br \/>\nString city<\/p>\n<p>}<\/p>\n<p>Person person = new Person(name:&quot;Mohit Garg&quot;,address:&quot;Address&quot;,city: &quot;city&quot;)<br \/>\nPerson person1 = new Person(&quot;Mohit Garg&quot;,&quot;Address&quot;,&quot;city&quot;)<\/p>\n<p>println(&quot;Check two objects are equal:::&quot;+(person.equals(person1)))  \/\/ Both objects will be equal because of same hashCode. (Output:true)<\/p>\n<p>println(&quot;person object:::&quot;+person) \/\/Output:Person(Mohit Garg, Address, city)<br \/>\n[\/groovy]<\/p>\n<p style=\"padding-bottom: 10px\">\n<p>Hope this will help you \ud83d\ude42<\/p>\n<p style=\"padding-bottom: 10px\">\n","protected":false},"excerpt":{"rendered":"<p>@Canonical: It&#8217;s very useful annotation. It provides the combination of features of @ToString (default implementation of toString() method based upon the fields in the class), @EqualsAndHashCode(default implementation of equals() and hashCode() method of the class based upon the fields in the class) and @TupleConstructor (provides the classical constructor with default properties). [groovy] import groovy.transform.Canonical @Canonical [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[1],"tags":[350,9],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8970"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=8970"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8970\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}