{"id":1322,"date":"2019-03-19T12:35:32","date_gmt":"2019-03-19T07:05:32","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=1322"},"modified":"2019-03-19T12:35:32","modified_gmt":"2019-03-19T07:05:32","slug":"learn-default-function-kotlin-suitable-example","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/","title":{"rendered":"Learn about Default function in Kotlin with suitable example here"},"content":{"rendered":"<p>In Java there is no concept of Default function .If you want to use your default function, which is already used in Kotlin,in your java you need to write @JvmOverloads for interoperability. Let see an example to make out-<\/p>\n<p><b>Ex-<\/b><\/p>\n<p>@file:JvmName(\u201cMyCustomKotlinName\u201d)<\/p>\n<p>fun main(args : Array&lt;String&gt;){<\/p>\n<p>var result = findVolumn(2, 3) \/\/height value has no need to write here<\/p>\n<p>return (result)<\/p>\n<p>}<\/p>\n<p>fun findVolumn(length : Int, breath : Int, height : Int = 10) : Int{ \/\/height is default =10<\/p>\n<p>return length * breath * height ;<\/p>\n<p>}<\/p>\n<p><b>output<\/b> :&#8211;&gt;<\/p>\n<p>60<\/p>\n<p>If you write height value in your main function that will overrides the previous value of height.<\/p>\n<p><b>Ex-<\/b><\/p>\n<p>fun main(args : Array&lt;String&gt;){<\/p>\n<p>var result = findVolumn(2, 3, 20) \/\/ overrides the value of height<\/p>\n<p>return (result)<\/p>\n<p>}<\/p>\n<p>fun findVolumn(length : Int, breath : Int, height : Int = 10) : Int{<\/p>\n<p>return length * breath * height ;<\/p>\n<p>}<\/p>\n<p><b>output<\/b> :&#8211;&gt;<\/p>\n<p>120<\/p>\n<p>If you want this function in your Java file then you have to write in this way&#8230;.<\/p>\n<p><b>i)<\/b> At first you have to write @JvmOverloads before starting this function.<\/p>\n<p><b>Ex<\/b>&#8211;<\/p>\n<p>@JvmOverloads<\/p>\n<p>fun findVolumn(length : Int, breath : Int, height : Int = 10) : Int{<\/p>\n<p>return length * breath * height ;<\/p>\n<p>}<\/p>\n<p><b>ii) <\/b>Then you can call this function in your java file.<\/p>\n<p><b>Ex<\/b>&#8211;<\/p>\n<p>MyCustomKotlinName . findVolumn(2, 3, 10);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Java there is no concept of Default function .If you want to use your default function, which is already used in Kotlin,in your java you need to write @JvmOverloads for interoperability. Let see an example to make out- Ex- @file:JvmName(\u201cMyCustomKotlinName\u201d) fun main(args : Array&lt;String&gt;){ var result = findVolumn(2, 3) \/\/height value has no need [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":1394,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[94],"tags":[95,87],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn about Default function in Kotlin with suitable example here<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn about Default function in Kotlin with suitable example here\" \/>\n<meta property=\"og:description\" content=\"In Java there is no concept of Default function .If you want to use your default function, which is already used in Kotlin,in your java you need to write @JvmOverloads for interoperability. Let see an example to make out- Ex- @file:JvmName(\u201cMyCustomKotlinName\u201d) fun main(args : Array&lt;String&gt;){ var result = findVolumn(2, 3) \/\/height value has no need [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-19T07:05:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/03\/Kotlin-For-Android-Developers-A-Classy-Handbook-With-Advantages-Disadvantages.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"682\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/03\/Kotlin-For-Android-Developers-A-Classy-Handbook-With-Advantages-Disadvantages.jpg\",\"width\":1024,\"height\":682},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/\",\"name\":\"Learn about Default function in Kotlin with suitable example here\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/#primaryimage\"},\"datePublished\":\"2019-03-19T07:05:32+00:00\",\"dateModified\":\"2019-03-19T07:05:32+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/990bda7c6fac1aa9c1ffde7745f42628\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/learn-default-function-kotlin-suitable-example\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/990bda7c6fac1aa9c1ffde7745f42628\",\"name\":\"Arindam Kundu\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1eea674a264b13f5b7c5895e36503137?s=96&r=g\",\"caption\":\"Arindam Kundu\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1322"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=1322"}],"version-history":[{"count":3,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1322\/revisions"}],"predecessor-version":[{"id":1396,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1322\/revisions\/1396"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/1394"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=1322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=1322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=1322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}