{"id":1103,"date":"2015-10-26T14:15:44","date_gmt":"2015-10-26T14:15:44","guid":{"rendered":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/?p=1103"},"modified":"2020-11-24T13:26:08","modified_gmt":"2020-11-24T13:26:08","slug":"duck-typing-and-java-8-method-references","status":"publish","type":"post","link":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/","title":{"rendered":"Duck Typing &#038; Java 8 Method References"},"content":{"rendered":"\n<p>Some programming languages provide a feature with the rather strange name \u201cduck typing\u201d. Unfortunately, Java is not one of them. In this post, I am going to briefly explain what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.<\/p>\n\n\n\n<p>The concept of duck typing is probably best known from JavaScript. The term \u201cduck typing\u201d probably originated in a poem by the American author <a href=\"https:\/\/de.wikipedia.org\/wiki\/James_Whitcomb_Riley\">James Whitcomb Riley<\/a>, which says:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u201cWhen I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.\u201d<\/p><\/blockquote>\n\n\n\n<p>What does that have to do with programming? Let us envision a function that expects a duck object as a parameter. In this function, we want to call up the duck\u2019s \u201cquack\u201d method. In many cases, we do not actually care whether the object submitted really is a duck, as long as it has a \u201cquack\u201d method with a corresponding signature. In duck typing, the question \u201cIs it a duck?\u201d is not, in fact, determined by the actual type of the object itself, but rather by the object\u2019s properties.<\/p>\n\n\n\n<p>The <a href=\"https:\/\/api.jquery.com\/jquery.ajax\/#jQuery-ajax-settings\">AJAX-Funktion von JQuery<\/a> constitutes another, more realistic example. It expects an argument that is an object containing a url value and a success callback (over-simplified; in fact, there are numerous other options in JQuery).<\/p>\n\n\n\n<p>Java does not support duck typing. The method signature has to specify the correct type for each argument. For example, an argument has to implement the \u201cduck\u201d interface. It is not enough for a class to have the same methods that are provided for in the interface; no, it is necessary to actually write&nbsp;implements Duck. The following example, which is based on the JQuery AJAX example, illustrates this:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    public interface Request {\n      String getUrl();\n      void callback(String result);\n    }\n    public class MyRequest implements Request {\n      public String getUrl() {\n        return \"http:\/\/blog.saxsys.de\";\n      }\n      public void callback(String result) {\n        System.out.println(result);\n      }\n    }\n    public void ajax(Request request) {\n      ...\n    }<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>I defined a Request interface and an implementing class called MyRequest. The getUrl method returns the target address, and our AJAX framework calls the callback method as soon as the response is received. As the ajax method requires an argument of the Request type, I can use an instance of MyRequest without difficulty. If, for example, I have the following class, the situation is entirely different:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    public class OtherRequest {\n      public getUrl(){\n        return \"http:\/\/stage-sgs.dsinet.de\";\n      }\n      public void callback(String result) {\n        System.out.println(result);\n      }\n    }<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Even though this class also has the two required methods with an identical signature, the ajax method would refuse an instance of this class because the class does not implement the Request interface. This can often be very annoying, especially if you cannot modify a given class yourself, i.e. you cannot simply add implements Request, e.g. if it comes from a third-party library.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Ad-Hoc implementation of interfaces<\/h2>\n\n\n\n<p>Some other programming languages handle this differently: <a href=\"https:\/\/www.haskell.org\/\">Haskell<\/a>, for example, does not have \u201cinterfaces\u201d like Java, but Haskell\u2019s \u201c<a href=\"http:\/\/learnyouahaskell.com\/types-and-typeclasses\">typeclasses<\/a>\u201d are more or less equivalent to interfaces. And here you can add types to any <a href=\"http:\/\/learnyouahaskell.com\/making-our-own-types-and-typeclasses#typeclasses-102\">typeclass<\/a>. at a later time, irrespective of the type definition. Thus, I could add my OtherRequest type to the Request typeclass without having to modify the source code of OtherRequest. After which, I can use OtherRequest values as parameters for functions that require the Request type.<\/p>\n\n\n\n<p>Let us look at an example:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    class Request r where\n      getUrl :: r -> String\n    ajax :: (Request r) => r -> IO ()\n    ajax r = do print $ getUrl r<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This defines a Request type class with a getUrl function that receives a specific request and returns a string. Consequently, every data type added to this type class has to provide such a function. Among them is the ajax function that receives a request and returns an IO action. The implementation shown here is merely a placeholder that does not actually execute an AJAX request, but only displays the URL in the command line. For this purpose, it can use the getUrl function because the latter has been defined in the type class.&nbsp; Thus, this corresponds to our AJAX library code.<\/p>\n\n\n\n<p>In our program, we can now define our own data type for our request. In order to be able to use the AJAX framework, we have to add our data type to the \u201cRequest\u201d type class:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    data OtherRequest = OtherRequest {url::String} deriving (Show)\n    instance Request OtherRequest where\n      getUrl = url\n    x = OtherRequest \"http:\/\/www.saxsys.de\"\n    ajax x<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The data keyword is used to define a new type in Haskell, which in our case is called \u201cOtherRequest\u201d and has a \u201curl\u201d string. With this, Haskell generates a \u201curl\u201d function with the signature OtherRequest -&gt; String, i.e. it receives an OtherRequest value and returns a string.<\/p>\n\n\n\n<p>Instance adds our type to the type class. The line \u201cgetUrl = url\u201d means that the \u201curl\u201d function of our type is to be used if \u201cgetUrl\u201d is called by the type class. We could also specify a different implementation at this point. This is similar to the situation in Java, where a method prescribed by an interface is implemented in a class.<\/p>\n\n\n\n<p>The end of the code segment shows how we can use this. We create an \u201cOtherRequest\u201d value and label it \u201cx\u201d. Then, the \u201cajax\u201d function is called with x as an argument. Since we have added \u201cOtherRequest\u201d to the \u201cRequest\u201d type class, this call works as expected.<\/p>\n\n\n\n<p>As Haskell is not an object-oriented language, this is not completely equivalent to Java. But the important point is that defining our type and adding it to the type class (i.e. implementing the interface) are two independent processes that can be executed in independent sections of the code. Even if the \u201cOtherRequest\u201d type came from a third-party library, we could still add it to the type class we need in order to be able to use it for our program. Therefore, this option is a good substitute for duck typing in terms of extensibility, in particular because it is even possible to abstract from the specific name (see \u201cgetUrl = url\u201d).<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Dynamic or static typing<\/h2>\n\n\n\n<p>Duck typing is usually primarily mentioned in connection with dynamically typed languages such as JavaScript. With those, objects are checked for the necessary methods and attributes at runtime. But duck typing is also possible with static typing. In that case, the verification of whether an object \u201cis a duck\u201d is done at the compile time. <a href=\"http:\/\/www.typescriptlang.org\/\">Typescript<\/a> is a good example. Our Request example above could look like this in TypeScript:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    interface Request {\n      getUrl(): string\n      callback(result: String)\n    }\n    class MyRequest implements Request {\n      getUrl() {\n        return \"http:\/\/example.org\";\n      }\n      callback(result: String) {\n        console.log(result);\n      }\n    }\n    class OtherRequest {\n      getUrl() {\n        return \"http:\/\/example.org\";\n      }\n      callback(result: String) {\n        console.log(result);\n      }\n    }\n    function ajax(request: Request) {\n    }\n    var r1 = new MyRequest();\n    var r2 = new OtherRequest();\n    ajax(r1);\n    ajax(r2);<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The ajax function expects an argument of the Request interface type. However, the compiler will also accept an instance of OtherRequest, even though this class does not expressly implement the interface\u2014the fact that all the methods with the correct signature exist is sufficient. You can test the code live <a href=\"http:\/\/www.typescriptlang.org\/Playground#src=interface%20Request%20{%0A%09getUrl%28%29%3A%20string%0A%09callback%28result%3A%20String%29%0A}%0A%0Aclass%20MyRequest%20implements%20Request%20{%0A%09getUrl%28%29%20{%0A%09%09return%20%22http%3A%2F%2Fexample.org%22%3B%0A%09}%0A%09callback%28result%3A%20String%29%20{%0A%09%09console.log%28result%29%3B%0A%09}%0A}%0A%0Aclass%20OtherRequest%20{%0A%09getUrl%28%29%20{%0A%09%09return%20%22http%3A%2F%2Fexample.org%22%3B%0A%09}%0A%09callback%28result%3A%20String%29%20{%0A%09%09console.log%28result%29%3B%0A%09}%0A}%0A%0A%0Afunction%20ajax%28request%3A%20Request%29%20{%0A%09%0A}%0A%0Avar%20r1%20%3D%20new%20MyRequest%28%29%3B%0Avar%20r2%20%3D%20new%20OtherRequest%28%29%3B%0A%0Aajax%28r1%29%3B%0Aajax%28r2%29%3B\">here<\/a>.<\/p>\n\n\n\n<p>Back to Java. As mentioned above, Java does not support duck typing. However, using the method references in Java 8 can achieve a similar effect that can be very useful in certain situations, even if it is less elegant. Especially if the class to be used cannot or is not supposed to be modified.<\/p>\n\n\n\n<p>The idea is to not only pass the object to a function, but also to specify how the function can get the necessary methods of the object. Let us look at the AJAX example again:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    public void ajax(Request request) {\n      String url = request.getUrl();\n      ...\n      String result = ...\n      request.callback(result);\n    }\n    public &lt;T> void ajax(T request, Function&lt;T,String> urlExtractor, BiConsumer&lt;T, String> callback) {\n      String url = urlExtractor.apply(request);\n      ...\n      String result = ...;\n      callback.accept(request, result);\n    }<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If you do not have much experience with the functional classes and interfaces of Java 8, the signature of the second overloaded ajax method may take some getting used to for you. First, the method defines a generic type parameter T without specifying any type limits. Consequently, any desired instance can be submitted as the first argument, provided that the functions submitted as the second and third argument match this type. The second argument is a function that returns a string (namely the URL) for a given object of the type T. The third argument submitted is a <em>BiConsumer<\/em>, i.e. a function that accepts two arguments (the Request object and the result string again) and does not have a return value. With lambdas, this function can now be called as follows:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    MyOtherRequest myRequest = new MyOtherRequest();\n    ajax(myRequest, req -> req.getUrl(), (req, result) - req.callback(result));<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Method references make it more legible:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    OtherRequest otherRequest = new OtherRequest();\n    ajax(myRequest, OtherRequest::getUrl, OtherRequest::callback);<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The line reads like this: Take this Request object. To get the URL, call the getUrl method on the Request object. To process the result, please call the callback method on the object. This approach is not duck typing, but you can use it in situations where you would otherwise wish to use duck typing. In a sense, the method signature expresses requirements for a given object that have to be supported by the object. The fact that the actual name of the methods does not matter with this option is another interesting aspect. OtherRequest could just as well have called its callback method \u201cCallMe_Now\u201d. Incidentally, we could also have done the ajax signature differently in this case:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>    public void ajax(Supplier&lt;String> urlSupplier, Consumer&lt;String> callback) {\n      String url = urlSupplier.get();\n      ...\n      callback.accept(\"das Result\");\n    }\n    \/\/ Aufruf\n    ajax(otherRequest::getUrl, otherRequest::callback);<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In this case, we directly submit a function for obtaining the URL and a function for processing the result. From the perspective of the ajax function, it does not matter whether there is a Request object or what type it is. What matters is the difference when calling the method: The method references in this case refer to the otherRequest instance (with a lower case initial), whereas in the example above, the method references referred to the class (OtherRequest with an upper case initial). From an API design point of view, this is the best alternative because the ajax method makes the least assumptions regarding the requester, which makes it highly composable. Nevertheless, there are situations where the \u201cquasi-duck typing\u201d option described above is necessary, and where you really want to receive objects as parameters. For example, we used this option when we developed the <a href=\"https:\/\/github.com\/sialcasa\/mvvmFX\/wiki\/ModelWrapper\">Model-Wrapper<\/a>, which is a part of <a href=\"https:\/\/sogehtsoftware.de\/2015\/07\/mvvmfx-model-view-viewmodel-javafx-teil-1\/\">mvvmFX<\/a>, in order to make the getter and setter methods of a wrapped object known.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The question of whether Java as a language should directly support duck typing, similar to the TypeScript alternative described above, is controversial. Just because a class has the same method signatures does not necessarily mean that it is truly compatible or technically appropriate. My impression is that many Java developers are rather defensive anyway, as evinced e.g. by the <a href=\"http:\/\/steve-yegge.blogspot.de\/2010\/07\/wikileaks-to-leak-5000-open-source-java.html\">discussion about \u201cfinal\u201d with respect to methods and classes<\/a>. Therefore, I believe it is unlikely that Java will get true duck typing anytime soon. The possibility of an ad-hoc implementation of interfaces, as described for Haskell above, does not seem to be on the list of extensions to be expected for the Java language in the near future either.<\/p>\n\n\n\n<p>In conclusion, we can state that the functional interfaces of Java 8 provide at least some relief in this respect. Instead of being forced to define specific, limited types for method arguments, they allow for the use of any desired arguments, provided that the interpretation of these arguments is clarified by means of functions. This facilitates the integration of third-party code and reduces coupling. And with method references, you can achieve an even better technical expression than with pure lambda expressions.<\/p>\n\n\n\n<p>But once again, the most important realization is this: It is always worthwhile to think outside the Java box and see what is possible with other programming languages and whether you can adapt that to suit your own needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some programming languages provide a feature with the rather strange name \u201cduck typing\u201d. Unfortunately, Java is not one of them. In this post, I am going to briefly explain what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.<\/p>\n","protected":false},"author":70,"featured_media":1106,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"categories":[12],"tags":[569,570,571,572,276,566,568],"topics":[],"class_list":["post-1103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-duck-typing","tag-java-method-references","tag-typing","tag-typification","tag-java","tag-interfaces","tag-programming-language"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Duck Typing &amp; Java 8 Method References - ZEISS Digital Innovation Blog<\/title>\n<meta name=\"description\" content=\"This post explaines what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Duck Typing &amp; Java 8 Method References - ZEISS Digital Innovation Blog\" \/>\n<meta property=\"og:description\" content=\"This post explaines what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/\" \/>\n<meta property=\"og:site_name\" content=\"Digital Innovation Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-26T14:15:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-24T13:26:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"426\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Manuel Mauky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manuel Mauky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/\",\"url\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/\",\"name\":\"Duck Typing & Java 8 Method References - ZEISS Digital Innovation Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png\",\"datePublished\":\"2015-10-26T14:15:44+00:00\",\"dateModified\":\"2020-11-24T13:26:08+00:00\",\"author\":{\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#\/schema\/person\/9ebfb0f3f562d20f6156630b4d1e5ff5\"},\"description\":\"This post explaines what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.\",\"breadcrumb\":{\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#primaryimage\",\"url\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png\",\"contentUrl\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png\",\"width\":640,\"height\":426},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Duck Typing &#038; Java 8 Method References\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#website\",\"url\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/\",\"name\":\"Digital Innovation Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#\/schema\/person\/9ebfb0f3f562d20f6156630b4d1e5ff5\",\"name\":\"Manuel Mauky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-content\/uploads\/sites\/3\/2024\/06\/Mauky_Manuel_Profilbild_300x300px-150x150.jpg\",\"contentUrl\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-content\/uploads\/sites\/3\/2024\/06\/Mauky_Manuel_Profilbild_300x300px-150x150.jpg\",\"caption\":\"Manuel Mauky\"},\"description\":\"Manuel has been working as a software developer at ZEISS Digital Innovation in G\u00f6rlitz since 2010. In addition to Java, he mainly deals with JavaScript and TypeScript and the development of modern web applications. He is also interested in functional programming and regularly gives lectures on these topics. Manuel studied computer science in G\u00f6rlitz and organizes the Java User Group G\u00f6rlitz.\",\"url\":\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/author\/enmanuelmauky\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Duck Typing & Java 8 Method References - ZEISS Digital Innovation Blog","description":"This post explaines what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/","og_locale":"en_US","og_type":"article","og_title":"Duck Typing & Java 8 Method References - ZEISS Digital Innovation Blog","og_description":"This post explaines what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.","og_url":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/","og_site_name":"Digital Innovation Blog","article_published_time":"2015-10-26T14:15:44+00:00","article_modified_time":"2020-11-24T13:26:08+00:00","og_image":[{"width":640,"height":426,"url":"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png","type":"image\/png"}],"author":"Manuel Mauky","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manuel Mauky","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/","url":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/","name":"Duck Typing & Java 8 Method References - ZEISS Digital Innovation Blog","isPartOf":{"@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#primaryimage"},"image":{"@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#primaryimage"},"thumbnailUrl":"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png","datePublished":"2015-10-26T14:15:44+00:00","dateModified":"2020-11-24T13:26:08+00:00","author":{"@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#\/schema\/person\/9ebfb0f3f562d20f6156630b4d1e5ff5"},"description":"This post explaines what duck typing is, and how to achieve at least a similar effect using the method references introduced in Java 8.","breadcrumb":{"@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#primaryimage","url":"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png","contentUrl":"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping.png","width":640,"height":426},{"@type":"BreadcrumbList","@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/duck-typing-and-java-8-method-references\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/"},{"@type":"ListItem","position":2,"name":"Duck Typing &#038; Java 8 Method References"}]},{"@type":"WebSite","@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#website","url":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/","name":"Digital Innovation Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#\/schema\/person\/9ebfb0f3f562d20f6156630b4d1e5ff5","name":"Manuel Mauky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/#\/schema\/person\/image\/","url":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-content\/uploads\/sites\/3\/2024\/06\/Mauky_Manuel_Profilbild_300x300px-150x150.jpg","contentUrl":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-content\/uploads\/sites\/3\/2024\/06\/Mauky_Manuel_Profilbild_300x300px-150x150.jpg","caption":"Manuel Mauky"},"description":"Manuel has been working as a software developer at ZEISS Digital Innovation in G\u00f6rlitz since 2010. In addition to Java, he mainly deals with JavaScript and TypeScript and the development of modern web applications. He is also interested in functional programming and regularly gives lectures on these topics. Manuel studied computer science in G\u00f6rlitz and organizes the Java User Group G\u00f6rlitz.","url":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/author\/enmanuelmauky\/"}]}},"author_meta":{"display_name":"Manuel Mauky","author_link":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/author\/enmanuelmauky\/"},"featured_img":"https:\/\/blogs.zeiss.com\/digital-innovation\/de\/wp-content\/uploads\/sites\/2\/2015\/10\/201510_ducktyping-600x399.png","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">Java<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Java<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">duck typing<\/a>","<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">Java method references<\/a>","<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">typing<\/a>","<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">typification<\/a>","<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">Java<\/a>","<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">Interfaces<\/a>","<a href=\"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/category\/java\/\" class=\"advgb-post-tax-term\">programming language<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">duck typing<\/span>","<span class=\"advgb-post-tax-term\">Java method references<\/span>","<span class=\"advgb-post-tax-term\">typing<\/span>","<span class=\"advgb-post-tax-term\">typification<\/span>","<span class=\"advgb-post-tax-term\">Java<\/span>","<span class=\"advgb-post-tax-term\">Interfaces<\/span>","<span class=\"advgb-post-tax-term\">programming language<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 10 years ago","modified":"Updated 5 years ago"},"absolute_dates":{"created":"Posted on October 26, 2015","modified":"Updated on November 24, 2020"},"absolute_dates_time":{"created":"Posted on October 26, 2015 2:15 pm","modified":"Updated on November 24, 2020 1:26 pm"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/posts\/1103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/users\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/comments?post=1103"}],"version-history":[{"count":4,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/posts\/1103\/revisions"}],"predecessor-version":[{"id":1177,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/posts\/1103\/revisions\/1177"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/media\/1106"}],"wp:attachment":[{"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/media?parent=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/categories?post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/tags?post=1103"},{"taxonomy":"topics","embeddable":true,"href":"https:\/\/blogs.zeiss.com\/digital-innovation\/en\/wp-json\/wp\/v2\/topics?post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}