{"id":6210,"date":"2021-02-18T07:04:57","date_gmt":"2021-02-18T07:04:57","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=6210"},"modified":"2024-04-12T10:25:28","modified_gmt":"2024-04-12T10:25:28","slug":"scala-type-bounds-upper-type-bounds-tour-of-scala","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/","title":{"rendered":"Scala &#8211; Bound Types"},"content":{"rendered":"\r\n<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Upper Type Bounds | Tour of Scala&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:6145,&quot;3&quot;:{&quot;1&quot;:0,&quot;3&quot;:1},&quot;14&quot;:{&quot;1&quot;:3,&quot;3&quot;:1},&quot;15&quot;:&quot;Arial&quot;}\">Upper Type Bounds | Tour of Scala<\/span><\/h2>\r\n<p>&nbsp;<\/p>\r\n<p><strong>Scala Upper Bounds<\/strong><\/p>\r\n\r\n\r\n\r\n<p>In Scala, upper type bounds are a feature that allows developers to specify constraints on type parameters in generic classes and methods. An upper type bound restricts the type parameter to be a subtype of a specified type.\u00a0<\/p>\r\n<p>For example, consider a generic class <code>Container[T]<\/code> where <code>T<\/code> is constrain by an upper type <code>&lt;: SomeType<\/code>. This means that <code>T<\/code> must be a subtype of <code>SomeType<\/code>, allowing instances of <code>Container<\/code> to hold only elements of type <code>T<\/code> or its subtypes.<\/p>\r\n<p>Upper type bounds are denoted using the <code>&lt;:<\/code> symbol followed by the upper bound type. Multiple upper type bounds can be specified using the <code>with<\/code> keyword.<\/p>\r\n<p>Upper type bounds are useful for enforcing type safety and expressing relationships between types in a flexible and reusable manner. They enable developers to write generic code that works with a specific subset of types, promoting code reuse and enhancing type safety in Scala applications.<\/p>\r\n<p>Understanding upper type bounds is important for writing generic and flexible Scala code that effectively leverages the type system to enforce constraints and ensure correctness at compile-time.<\/p>\r\n\r\n\r\n\r\n<p>A program to demonstrate scala <a href=\"https:\/\/prwatech.in\/blog\/#\">upper<\/a> <a href=\"https:\/\/www.scala-lang.org\/\">bounds<\/a>:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"470\" class=\"wp-image-6211\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png 601w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521-300x235.png 300w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>Scala Lower Bounds<\/strong><\/p>\r\n\r\n\r\n\r\n<p>A program to demonstrate Scala Lower Bounds:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"465\" class=\"wp-image-6212\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-523.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-523.png 598w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-523-300x233.png 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>Scala View Bound<\/strong><\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"301\" class=\"wp-image-6214\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-525.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-525.png 511w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-525-300x177.png 300w\" sizes=\"auto, (max-width: 511px) 100vw, 511px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>Upper Type Bounds | Tour of Scala<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Upper Type Bounds | Tour of Scala &nbsp; Scala Upper Bounds In Scala, upper type bounds are a feature that allows developers to specify constraints on type parameters in generic classes and methods. An upper type bound restricts the type parameter to be a subtype of a specified type.\u00a0 For example, consider a generic class [&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":[2004,2002,576,2003],"class_list":["post-6210","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-upper-bound","tag-lower-type-bounds-tour-of-scala","tag-scala","tag-scala-generics-i-upper-and-lower-scala-type-bounds"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Upper Type Bounds | Tour of Scala - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Upper Type Bounds | Tour of 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=\"Upper Type Bounds | Tour of Scala - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Upper Type Bounds | Tour of 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-type-bounds-upper-type-bounds-tour-of-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-02-18T07:04:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T10:25:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png\" \/>\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-type-bounds-upper-type-bounds-tour-of-scala\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/\",\"name\":\"Upper Type Bounds | Tour of Scala - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png\",\"datePublished\":\"2021-02-18T07:04:57+00:00\",\"dateModified\":\"2024-04-12T10:25:28+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Upper Type Bounds | Tour of Scala - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png\",\"width\":601,\"height\":470},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Bound Types\"}]},{\"@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":"Upper Type Bounds | Tour of Scala - Prwatech","description":"Master Upper Type Bounds | Tour of 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":"Upper Type Bounds | Tour of Scala - Prwatech","og_description":"Master Upper Type Bounds | Tour of Scala - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2021-02-18T07:04:57+00:00","article_modified_time":"2024-04-12T10:25:28+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png","type":"","width":"","height":""}],"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-type-bounds-upper-type-bounds-tour-of-scala\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/","name":"Upper Type Bounds | Tour of Scala - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png","datePublished":"2021-02-18T07:04:57+00:00","dateModified":"2024-04-12T10:25:28+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Upper Type Bounds | Tour of Scala - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/02\/Screenshot-521.png","width":601,"height":470},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-type-bounds-upper-type-bounds-tour-of-scala\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Bound Types"}]},{"@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\/6210","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=6210"}],"version-history":[{"count":8,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/6210\/revisions"}],"predecessor-version":[{"id":11382,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/6210\/revisions\/11382"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=6210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=6210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=6210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}