{"id":8620,"date":"2021-05-22T16:04:42","date_gmt":"2021-05-22T16:04:42","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=8620"},"modified":"2024-04-13T11:22:00","modified_gmt":"2024-04-13T11:22:00","slug":"scala-empty-values-dealing-with-null-values-in-scala","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/","title":{"rendered":"Scala &#8211; Empty Values"},"content":{"rendered":"\r\n<h2>Dealing with Null Values in Scala<\/h2>\r\n<p>&nbsp;<\/p>\r\n<p>The Empty values in <a href=\"https:\/\/prwatech.in\/blog\/scala\/scala-a-quick-overview\/\">Scala<\/a> are <a href=\"http:\/\/scala-lang.org\">addressed<\/a> by Null, null, Nil, Nothing, None, and Unit. The explanation of these vacant qualities are as per the following:<\/p>\r\n\r\n\r\n\r\n<p>\u2022 <strong>null:<\/strong> The reference types, for example, Objects, and Strings can be invalid and the worth kinds like Int, Double, Long, and so forth, can&#8217;t be invalid, the invalid in Scala is practically equivalent to the invalid in Java.<\/p>\r\n\r\n\r\n\r\n<p>\u2022 <strong>Null:<\/strong> it is a Trait, which is a subset of every one of the reference types however isn&#8217;t at all a sub-kind of significant worth sorts and a solitary occurrence of Null will be invalid. The reference types can be alloted invalid yet the worth kinds can&#8217;t be allocated invalid.Dealing with Null Values in Scala<\/p>\r\n\r\n\r\n\r\n<p><strong>Use case 1:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\r\nobject prwatech {\r\n  \/\/ Main method\r\n    def main(args: Array[String]) \r\n    {\r\n        \/\/ Method that takes a parameter of type Null\r\n        def usingnull(thing: Null): Unit = \r\n        { \r\n            println(\"Prwatech\"); \r\n        }\r\n  \r\n        \/*error: type mismatch;\r\n  \r\n        found   : java.lang.String(\"hey\")\r\n  \r\n        required: Null*\/\r\n        \/\/usingnull(\"hey\")\r\n  \r\n        \/\/ passing null itself\r\n        usingnull(null)\r\n    }\r\n}\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p><strong>output:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>Prwatech\r\n\r\nHere, method usingnull consists a parameter of type Null, here we can only pass two things. null itself or a reference of type Null. when a string is passed as argument it didn\u2019t work and generated an error.\r\n\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>\u2022 <strong>Nothing<\/strong>: Nothing is likewise a Trait, which has no occurrences. It is a subset of every one of the unmistakable sorts. The significant intention of this Trait is to supply a return type for the strategies which reliably tosses a special case i.e, not so much as a solitary time returns for the most part. It is additionally useful in giving a sort to Nil.<\/p>\r\n\r\n\r\n\r\n<p>\u2022<strong> Unit:<\/strong> The Unit is Scala is similar to the void in Java, which is use as a return sort of a capacities that is utilize with a capacity when the expresse capacity doesn&#8217;t brings anything back.<\/p>\r\n\r\n\r\n\r\n<p><strong>Use case 2:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>object prwatech {\r\n  \/\/ Main method\r\n    def main(args: Array[String]) \r\n    {\r\n        \/\/ Method return type is unit\r\n        def printNumber(num: (Int) =&gt; Unit) = \r\n        {\r\n  \r\n            num(1); \r\n            num(2); \r\n            num(3);\r\n        }\r\n          \r\n        printNumber(println)\r\n    }\r\n}\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>1\r\n2\r\n3\r\n\r\nHere, method printNumber takes a parameter called num, which has a type of (Int) =&gt; Unit. This means that num is a method that contains a single parameter of type Int. method printNumber return type of Unit, which means num should not return a value.<\/code><\/pre>\r\n\r\n\r\n\r\n<p><strong>Nil<\/strong>: Nil is Consider as a List which has zero components in it. The kind of Nil is List[Nothing] and as express over, that Nothing has no occurrences, we can have a List which is affirm to be devastate.<\/p>\r\n\r\n\r\n\r\n<p><strong>Use case 3:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>object prwatech {\r\n \/\/ Main method\r\n    def main(args: Array[String]) \r\n    {\r\n  \r\n        \/\/ Displays empty list\r\n        println(Nil)\r\n    }\r\n}\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p><strong>Output:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>List()\r\n\r\nThus, we can see that an empty list is returned.\r\n<\/code><\/pre>\r\n","protected":false},"excerpt":{"rendered":"<p>Dealing with Null Values in Scala &nbsp; The Empty values in Scala are addressed by Null, null, Nil, Nothing, None, and Unit. The explanation of these vacant qualities are as per the following: \u2022 null: The reference types, for example, Objects, and Strings can be invalid and the worth kinds like Int, Double, Long, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,1698],"tags":[1347,1350,1352,1344,1353,1349,1348,1351,1345,1346],"class_list":["post-8620","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-empty-value-overview","tag-empty-value-use-cases-in-scala","tag-empty-values","tag-empty-values-scala","tag-explain-empty-values","tag-how-empty-values-work-in-scala","tag-scala-empty-value-definition","tag-scala-empty-value-implementation","tag-scala-empty-values","tag-what-is-empty-value-in-scala"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dealing with Null Values in Scala - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Dealing with Null Values in Scala - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dealing with Null Values in Scala - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Dealing with Null Values in Scala - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-22T16:04:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-13T11:22:00+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/\",\"name\":\"Dealing with Null Values in Scala - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2021-05-22T16:04:42+00:00\",\"dateModified\":\"2024-04-13T11:22:00+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Dealing with Null Values in Scala - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Empty Values\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dealing with Null Values in Scala - Prwatech","description":"Master Dealing with Null Values in Scala - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Dealing with Null Values in Scala - Prwatech","og_description":"Master Dealing with Null Values in Scala - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2021-05-22T16:04:42+00:00","article_modified_time":"2024-04-13T11:22:00+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/","name":"Dealing with Null Values in Scala - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2021-05-22T16:04:42+00:00","dateModified":"2024-04-13T11:22:00+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Dealing with Null Values in Scala - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-empty-values-dealing-with-null-values-in-scala\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Empty Values"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=8620"}],"version-history":[{"count":6,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8620\/revisions"}],"predecessor-version":[{"id":11459,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8620\/revisions\/11459"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=8620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=8620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=8620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}