{"id":4297,"date":"2011-10-04T19:14:27","date_gmt":"2011-10-04T13:44:27","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4297"},"modified":"2022-01-12T19:01:29","modified_gmt":"2022-01-12T13:31:29","slug":"closure-as-an-implementation-to-interface","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/","title":{"rendered":"Closure as an implementation to interface"},"content":{"rendered":"<p>Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of &#8216;as&#8217; operator. The &#8216;as&#8217; operator of groovy is typically used to change the types of objects.<\/p>\n<p>For example:<br \/>\n[groovy]<br \/>\nint a = &quot;20&quot; as int<br \/>\nassert a==20<br \/>\n[\/groovy]<\/p>\n<p>The &#8216;as&#8217; operator can be used to provide implementation to interface as well. Here is an example of the same:<\/p>\n<p>[groovy]<br \/>\ninterface Eatable{<br \/>\n   void eat()<br \/>\n}<\/p>\n<p>def x =  {println &quot;It&#8217;s groovy style&quot; } as Eatable<br \/>\nx.eat()<br \/>\n[\/groovy]<\/p>\n<p>Had it been java, this could have been achieved through an annonymous class like this:<\/p>\n<p>[java]<br \/>\nnew Eatable(){<br \/>\n  void eat(){<br \/>\n    System.out.println &quot;Its java style&quot;<br \/>\n  }<br \/>\n}.eat()<br \/>\n[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of &#8216;as&#8217; operator. The &#8216;as&#8217; operator of groovy is typically used to change the types of objects. For example: [groovy] int a = &quot;20&quot; as int assert a==20 [\/groovy] The &#8216;as&#8217; operator can be used to provide implementation to interface as [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":15,"footnotes":""},"categories":[7],"tags":[358,845,426,9],"class_list":["post-4297","post","type-post","status-publish","format-standard","hentry","category-grails","tag-closure","tag-coding-style","tag-design-pattern","tag-groovy"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of &#039;as&#039; operator. The &#039;as&#039; operator of groovy is typically used to change the types of objects. For example: [groovy] int a = &quot;20&quot; as int assert a==20 [\/groovy] The &#039;as&#039; operator can be used to provide implementation to interface as\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Mohd Farid\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Closure as an implementation to interface | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of &#039;as&#039; operator. The &#039;as&#039; operator of groovy is typically used to change the types of objects. For example: [groovy] int a = &quot;20&quot; as int assert a==20 [\/groovy] The &#039;as&#039; operator can be used to provide implementation to interface as\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Closure as an implementation to interface | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of &#039;as&#039; operator. The &#039;as&#039; operator of groovy is typically used to change the types of objects. For example: [groovy] int a = &quot;20&quot; as int assert a==20 [\/groovy] The &#039;as&#039; operator can be used to provide implementation to interface as\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#article\",\"name\":\"Closure as an implementation to interface | TO THE NEW Blog\",\"headline\":\"Closure as an implementation to interface\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/farid\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2011-10-04T19:14:27+05:30\",\"dateModified\":\"2022-01-12T19:01:29+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#webpage\"},\"articleSection\":\"Grails, closure, coding Style, Design Pattern, Groovy\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#listItem\",\"name\":\"Closure as an implementation to interface\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#listItem\",\"position\":3,\"name\":\"Closure as an implementation to interface\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/farid\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/farid\\\/\",\"name\":\"Mohd Farid\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d386ff6714165be4c5ee1f75fd255d6ca7021e0ada16952088cff7e9f6e50679?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Mohd Farid\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/\",\"name\":\"Closure as an implementation to interface | TO THE NEW Blog\",\"description\":\"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of 'as' operator. The 'as' operator of groovy is typically used to change the types of objects. For example: [groovy] int a = \\\"20\\\" as int assert a==20 [\\\/groovy] The 'as' operator can be used to provide implementation to interface as\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/closure-as-an-implementation-to-interface\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/farid\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/farid\\\/#author\"},\"datePublished\":\"2011-10-04T19:14:27+05:30\",\"dateModified\":\"2022-01-12T19:01:29+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Closure as an implementation to interface | TO THE NEW Blog","description":"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of 'as' operator. The 'as' operator of groovy is typically used to change the types of objects. For example: [groovy] int a = \"20\" as int assert a==20 [\/groovy] The 'as' operator can be used to provide implementation to interface as","canonical_url":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#article","name":"Closure as an implementation to interface | TO THE NEW Blog","headline":"Closure as an implementation to interface","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/farid\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2011-10-04T19:14:27+05:30","dateModified":"2022-01-12T19:01:29+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#webpage"},"articleSection":"Grails, closure, coding Style, Design Pattern, Groovy"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#listItem","name":"Closure as an implementation to interface"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#listItem","position":3,"name":"Closure as an implementation to interface","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/farid\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/farid\/","name":"Mohd Farid","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d386ff6714165be4c5ee1f75fd255d6ca7021e0ada16952088cff7e9f6e50679?s=96&d=mm&r=g","width":96,"height":96,"caption":"Mohd Farid"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/","name":"Closure as an implementation to interface | TO THE NEW Blog","description":"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of 'as' operator. The 'as' operator of groovy is typically used to change the types of objects. For example: [groovy] int a = \"20\" as int assert a==20 [\/groovy] The 'as' operator can be used to provide implementation to interface as","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/farid\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/farid\/#author"},"datePublished":"2011-10-04T19:14:27+05:30","dateModified":"2022-01-12T19:01:29+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Closure as an implementation to interface | TO THE NEW Blog","og:description":"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of 'as' operator. The 'as' operator of groovy is typically used to change the types of objects. For example: [groovy] int a = &quot;20&quot; as int assert a==20 [\/groovy] The 'as' operator can be used to provide implementation to interface as","og:url":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Closure as an implementation to interface | TO THE NEW Blog","twitter:description":"Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of 'as' operator. The 'as' operator of groovy is typically used to change the types of objects. For example: [groovy] int a = &quot;20&quot; as int assert a==20 [\/groovy] The 'as' operator can be used to provide implementation to interface as","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"4297","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-65e03f363d54a","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2021-04-29 12:10:39","updated":"2024-02-29 08:24:22","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tClosure as an implementation to interface\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Closure as an implementation to interface","link":"https:\/\/www.tothenew.com\/blog\/closure-as-an-implementation-to-interface\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4297","targetHints":{"allow":["GET"]}}],"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\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4297"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4297\/revisions"}],"predecessor-version":[{"id":54610,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4297\/revisions\/54610"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}