{"id":77313,"date":"2020-03-20T10:12:16","date_gmt":"2020-03-20T04:42:16","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77313"},"modified":"2020-03-20T10:12:16","modified_gmt":"2020-03-20T04:42:16","slug":"java-generics","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-generics\/","title":{"rendered":"Java Generics &#8211; Get one step closer to become a Java Expert!"},"content":{"rendered":"<p>Suppose we have to make a list of human beings living in society. It doesn&#8217;t matter whether it&#8217;s a child, teen or adult. All that matters is they should be human. In such cases, we will not categorize them and will group them as a &#8220;Human Being&#8221;.<\/p>\n<p>Similarly in Java when we store data we focus on the content and not datatype and that&#8217;s where Generics are used. Java Generics is a programming-language feature that allows for the definition and use of generic methods and generic types.<\/p>\n<p>Today in this Java tutorial, we are going to study the Generics in Java and it&#8217;s Class with multiple parameters. We will also discuss various features and functions of generics in Java.<\/p>\n<p>At last, we will learn how to use generics in Java to improve the quality of the code with the help of examples.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/advantages-of-java-generics.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77602\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/advantages-of-java-generics.jpg\" alt=\"Java Generics Advantages\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<h3>Java Generics<\/h3>\n<p>Java introduced the concept of Generics since Java 5 (J2SE 5) to deal with compile-time type checking and removing the risk of <strong>ClassCastException<\/strong> that was common while working with collection classes. Generics in Java is one of the most important features introduced since Java 5.<\/p>\n<p>The term Generics in Java represents a set of features in a language, that relates to defining and using the generic methods and types. In Java, Generic methods and types are different from regular methods and types. They differ from each other as generic methods have type parameters.<\/p>\n<p>We can see Java Generics as the <strong>templates in C++<\/strong>. Using Java Generics, we can use the wrapper classes like Integer, String, Double, etc and user-defined types as the parameters to classes, methods, and interfaces.<\/p>\n<p>We can utilize the generics for any kind. For example,\u00a0classes like HashSet, ArrayList, HashMap, etc use the Java Generics very well.<\/p>\n<h3>Need for Java Generics<\/h3>\n<p>Java Generics allow us to write a single method that could be able to perform operations in various types of objects that support that method.<\/p>\n<p>Using Java Generic classes and methods, programmers can specify a set of related methods with a single\/generic method declaration, or with a single class declaration.<\/p>\n<p>For example, the Java Generics concept allows us to write a generic method for sorting an array of different types of objects, like to invoke the generic method with Character arrays, Integer arrays, String arrays, Double arrays and so on to sort the array elements.<\/p>\n<p>Moreover, Java Generics provide compile-time type safety that allows the programmers to catch invalid types or faults during compilation.<\/p>\n<p><em><strong>Get to know more about <a href=\"https:\/\/techvidvan.com\/tutorials\/java-array\/\">Java Array<\/a> in detail with Techvidvan.<\/strong><\/em><\/p>\n<h3>Java Generic Classes<\/h3>\n<p>A generic class is a class that can refer to any type. To create a generic class of a specific type, we put the T type parameter. The angular brackets <strong>&lt;&gt;<\/strong> are used to specify parameter types in Java generic class creation.<\/p>\n<p><em><strong>Dive a little deep into the concept of <a href=\"https:\/\/techvidvan.com\/tutorials\/java-class\/\">Classes in Java<\/a> to clear your basics.<\/strong><\/em><\/p>\n<p>Let\u2019s discuss a simple example to create and use the generic class.<\/p>\n<h3>Creating a Generic Class<\/h3>\n<p>The declaration of a generic class is similar to a non-generic class declaration, the only difference is that the generic class name is followed by a type parameter section. The following code shows the creation of a generic class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class MyGenClass&lt;T&gt;\n{\n       T obj;\n       void add(T obj)\n       {\n              this.obj=obj;\n       }\n       T getObj()\n       {\n              return obj;\n       }\n}<\/pre>\n<p>Here, the type T indicates that it can refer to any type of class like Integer, String, Double, Character, and Employee, etc. The specified type of class will store and retrieve the data of the same type.<\/p>\n<p><em><strong>Note:<\/strong> In Parameter type, we cannot use primitives data types like \u2018int\u2019,\u2019char\u2019 or \u2018double\u2019, etc.<\/em><\/p>\n<h3>Using a Generic Class<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class TestGenerics3\n{\n       public static void main(String args[])\n       {\n              MyGenClass&lt;Integer&gt; myObj = new MyGenClass&lt;Integer&gt;();\n              myObj.add(18);\n              \/\/myObj.add(\"TechVidvan\"); \/\/Compile-time error\n              System.out.println(myObj.getObj());\n       }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">18<\/div>\n<p><strong>Code to understand Generic Classes:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.javagenerics;\n\/\/ We use &lt; &gt; to specify Parameter type\nclass MyGenericClass&lt;T&gt;\n{\n  \/\/ Declaring an object of type T\n  T obj;\n  \/\/ constructor\n  MyGenericClass(T obj)\n  {\n    this.obj = obj;\n  }\n  public T getObject()\n  {\n    return this.obj;\n  }\n}\nclass GenericClassDemo\n{\n  public static void main (String[] args)\n  {\n    \/\/Using Generic class for Integers\n    MyGenericClass &lt;Integer&gt; intObj = new MyGenericClass&lt;Integer&gt;(15);\n    System.out.println(intObj.getObject());\n\n    \/\/Using Generic class for String\n    MyGenericClass&lt;String&gt; stringObj = new MyGenericClass&lt;String&gt;(\"TechVidvan\");\n    System.out.println(stringObj.getObject());\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">15<br \/>\nTechVidvan<\/div>\n<h3>Using Multiple type Parameters in Generic Classes<\/h3>\n<p>We can also use multiple parameters of different types in a generic class, that is, the parameter type section of a generic class can have more than one type of parameter separated by commas.<\/p>\n<p>These classes are known as <strong>parameterized classes<\/strong> since they accept more than one parameter.<\/p>\n<p><strong>Code to illustrate multiple type Parameters in Generic Classes:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.javagenerics;\nclass Test&lt;T, U&gt;\n{\n  T obj1; \/\/ An object of type T\n  U obj2; \/\/ An object of type U\n  \/\/ constructor\n  Test(T obj1, U obj2)\n  {\n    this.obj1 = obj1;\n    this.obj2 = obj2;\n  }\n  \/\/ To print objects of T and U\n  public void getObject()\n  {\n    System.out.println(\u201cString value: \u201c +obj1);\n    System.out.println(\u201cInteger value: \u201d +obj2);\n  }\n}\nclass Main\n{\n  public static void main (String[] args)\n  {\n    Test &lt;String, Integer&gt; obj = new Test&lt;String, Integer&gt;(\"TechVidvan\", 15);\n    obj.getObject();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">String value: TechVidvan<br \/>\nInteger value: 15<\/div>\n<h4>Type Parameters<\/h4>\n<p>The type parameter\u2019s naming conventions are crucial for learning generics thoroughly. The common type parameters are as follows:<\/p>\n<ol>\n<li>T &#8211; Type<\/li>\n<li>E &#8211; Element<\/li>\n<li>K &#8211; Key<\/li>\n<li>N &#8211; Number<\/li>\n<li>V &#8211; Value<\/li>\n<\/ol>\n<h3>Java Generic Methods<\/h3>\n<p>We can declare a single generic method and we can call this method with arguments of different types. The compiler handles each method call appropriately according to the types of the arguments passed to the generic method.<\/p>\n<h3>Rules to define Generic Methods<\/h3>\n<ul>\n<li>There should be a type parameter section in all generic method declarations, delimited by angular brackets <strong>&lt;&gt;<\/strong> that precede the method&#8217;s return type.<\/li>\n<li>If there is more than one parameter in the parameter list then each type parameter should be separated by commas.<\/li>\n<li>We can also use the type parameters to declare the return type and let them act as placeholders for the types of arguments passed to the generic method, called as actual type arguments.<\/li>\n<li>The method body of a generic method is declared similar to any other non-generic method.<\/li>\n<li>The type parameter in a method can represent only reference types, non-primitive types like int, double and char.<\/li>\n<\/ul>\n<p><em><strong>Get familiar with the concept of <a href=\"https:\/\/techvidvan.com\/tutorials\/data-types-in-java\/\">Data types in Java<\/a> in detail with Techvidvan.<\/strong><\/em><\/p>\n<p><strong>Code to understand Generic Methods:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.javagenerics;\npublic class GenericMethodDemo\n{\n  \/\/ defining generic method printArray\n  public static &lt; E &gt; void printArray( E[] inputArray )\n  {\n    \/\/ Displaying array elements\n    for(E element : inputArray)\n    {\n      System.out.printf(\"%s \", element);\n    }\n    System.out.println();\n  }\n\n  public static void main(String args[])\n  {\n    \/\/ Create arrays of Integer, Double and Character\n    Integer[] intArray = { 10, 20, 30, 40, 50 };\n    Double[] doubleArray = { 1.2, 2.5, 4.6, 7.8 };\n    Character[] charArray = { 'T', 'e', 'c', 'h', 'V', 'i', 'd', 'V', 'a', 'N' };\n\n    System.out.println(\"Array integerArray contains:\");\n    printArray(intArray); \/\/ pass an Integer array\n\n    System.out.println(\"\\nArray doubleArray contains:\");\n    printArray(doubleArray); \/\/ pass a Double array\n\n    System.out.println(\"\\nArray characterArray contains:\");\n    printArray(charArray); \/\/ pass a Character array\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Array integerArray contains:<br \/>\n10 20 30 40 50<br \/>\nArray doubleArray contains:<br \/>\n1.2 2.5 4.6 7.8<br \/>\nArray characterArray contains:<br \/>\nT e c h V i d V a n<\/div>\n<h3>What is not allowed to do with Java Generics?<\/h3>\n<p>Now, we will discuss some tasks that are not allowed to do in Java Generics. So let\u2019s examine each of them.<\/p>\n<h4>a) You can\u2019t have a static field of type<\/h4>\n<p>In your generic class, you can not define a static generic parameterized member. Any attempt to do so will generate a compile-time error. The error will be like: Cannot make a static reference to the non-static type T.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class GenericClass&lt;T&gt;\n{\n        private static T member; \t\/\/This is not allowed\n}<\/pre>\n<h4>b) You can not create an instance of T<\/h4>\n<p>We can also not create an object of T. Any attempt to do so will fail with an error: Cannot instantiate the type T. For example,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class GenericClass&lt;T&gt;\n{\n        public GenericClass()\t\t\/\/Constructor created\n  {\n    new T();\t\/\/Not Allowed\n  }\n}<\/pre>\n<h4>c) We can\u2019t use primitive data types with Generics declaration<\/h4>\n<p>We can\u2019t declare generic expressions like List or Map &lt;int, double&gt;. But, we can use the <em><strong>wrapper classes<\/strong><\/em> in place of primitive data types and then use the primitives while passing the actual values. Auto-boxing converts these primitive types to their respective wrapper classes.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">final HashMap&lt;int&gt; id = new HashMap&lt;&gt;();\t\t\/\/Not allowed\n\nfinal HashMap&lt;Integer&gt; id = new HasMap&lt;&gt;();\t\/\/Allowed<\/pre>\n<h4>d) You can\u2019t create Generic exception class<\/h4>\n<p>We can\u2019t pass an instance of generic type along with exception being thrown. This is not allowed in Java. For example, the following line causes an error.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\/\/ causes compiler error\npublic class GenericClass&lt;T&gt; extends Exception {}<\/pre>\n<p>When you try to do this, you will get an error message like this: The generic class <strong>GenericException<\/strong> may not subclass <strong>java.lang.Throwable.<\/strong><\/p>\n<h3>Advantages of Java Generics<\/h3>\n<p>Applications that make use of Java Generics have several benefits over the non-generic code. Some of them are as follows &#8211;<\/p>\n<h4>1. Code Reuse<\/h4>\n<p>We can create a generic strategy or a class or an interface once and use it for any type we need and for any number of times.<\/p>\n<p><em><strong>For better understanding, you must explore the concept of <a href=\"https:\/\/techvidvan.com\/tutorials\/java-interface\/\">Java Interface <\/a>in detail.<\/strong><\/em><\/p>\n<h4>2. Sort Safety<\/h4>\n<p>It is better to know the faults and issues in your code at compile-time rather than at run-time. Java Generics enables you to detect the faults at compile-time than at runtime.<\/p>\n<p>Suppose, you need to make an ArrayList that stores the name of undergraduate students and if by mistake, software engineer includes an integer in place of a string, compiler permits it. However, when we try to gain this information from ArrayList, it causes issues at runtime.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Test\n{\n  \t     public static void main(String[] args)\n  \t     {\n  \t       \t     \/\/ Creating an ArrayList with String specified\n  \t       \t     ArrayList &lt;String&gt; al = new ArrayList&lt;String&gt; ();\n  \t       \t     al.add(\"Sachin\");\n  \t       \t     al.add(\"Rahul\");\n  \t       \t     \/\/Type Casting is required\n  \t       \t     String s1 = (String)al.get(0);\n  \t       \t     String s2 = (String)al.get(1);\n  \t       \t     String s3 = (String)al.get(2);\n  \t     }\n}<\/pre>\n<h4>3. Individual Type Casting isn\u2019t required<\/h4>\n<p>In the above case, if we don\u2019t use Java generics, at that point, we need to typecast the ArrayList each time we recover information from it. It is a major headache to typecast at each recovery.<\/p>\n<p>If we utilize the Java generics in our code, then we need not do typecasting at each recovery. The below code shows this concept:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Test\n{\n \t     public static void main(String[] args)\n \t     {\n \t      \t     \/\/ Creating an ArrayList with String specified\n \t      \t     ArrayList &lt;String&gt; al = new ArrayList&lt;String&gt; ();\n \t      \t     al.add(\"Sachin\");\n \t      \t     al.add(\"Rahul\");\n \t      \t     \/\/ Typecasting is not needed\n \t      \t     String s1 = al.get(0);\n \t      \t     String s2 = al.get(1);\n \t     }\n}<\/pre>\n<h4>4. Implementing non-generic algorithms<\/h4>\n<p>We can perform the calculations that work on various sorts of items by utilizing generics in <a href=\"https:\/\/www.oracle.com\/java\/technologies\/javase-downloads.html\">Java<\/a>, and they are type-safe as well.<\/p>\n<h3>Summary<\/h3>\n<p>To use Java Generics for achieving type-safety, the whole collection framework was re-written. With this, we come to the end of our article on Java Generics.<\/p>\n<p>In this article, we learned the basic concept of Java Generics along with its classes, methods, and uses. We also covered some advantages and need for Generics in Java with examples.<\/p>\n<p>That was all about Java Generics. I hope this article helped you in understanding the concept of Java Generics.<\/p>\n<p>Happy Learning \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Suppose we have to make a list of human beings living in society. It doesn&#8217;t matter whether it&#8217;s a child, teen or adult. All that matters is they should be human. In such cases,&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77602,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2044,2045,2046,2047,2048,2049,2050,2051,2052,2053],"class_list":["post-77313","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-advantages-of-generics-in-java","tag-generics-in-java","tag-java-generics","tag-java-generics-class","tag-java-generics-example","tag-java-generics-methods","tag-java-generics-need","tag-java-generics-rules","tag-java-generics-tutorial","tag-using-java-generics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Generics - Get one step closer to become a Java Expert! - TechVidvan<\/title>\n<meta name=\"description\" content=\"Understand the concept of Java Generics along with its classes, methods, &amp; uses. We also covered some advantages &amp; need for Generics in Java with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-generics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Generics - Get one step closer to become a Java Expert! - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Understand the concept of Java Generics along with its classes, methods, &amp; uses. We also covered some advantages &amp; need for Generics in Java with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-generics\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-20T04:42:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-java-generics.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Generics - Get one step closer to become a Java Expert! - TechVidvan","description":"Understand the concept of Java Generics along with its classes, methods, & uses. We also covered some advantages & need for Generics in Java with examples.","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:\/\/techvidvan.com\/tutorials\/java-generics\/","og_locale":"en_US","og_type":"article","og_title":"Java Generics - Get one step closer to become a Java Expert! - TechVidvan","og_description":"Understand the concept of Java Generics along with its classes, methods, & uses. We also covered some advantages & need for Generics in Java with examples.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-generics\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-03-20T04:42:16+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-java-generics.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java Generics &#8211; Get one step closer to become a Java Expert!","datePublished":"2020-03-20T04:42:16+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/"},"wordCount":1471,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-java-generics.jpg","keywords":["Advantages of Generics in java","Generics in Java","Java Generics","Java Generics class","Java Generics example","Java Generics Methods","Java Generics Need","Java Generics Rules","Java Generics tutorial","Using Java Generics"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-generics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/","url":"https:\/\/techvidvan.com\/tutorials\/java-generics\/","name":"Java Generics - Get one step closer to become a Java Expert! - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-java-generics.jpg","datePublished":"2020-03-20T04:42:16+00:00","description":"Understand the concept of Java Generics along with its classes, methods, & uses. We also covered some advantages & need for Generics in Java with examples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-generics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-java-generics.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-java-generics.jpg","width":802,"height":420,"caption":"Java Generics Advantages"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-generics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java Generics &#8211; Get one step closer to become a Java Expert!"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77313"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77313\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77602"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}