{"id":7371,"date":"2022-08-12T13:14:13","date_gmt":"2022-08-12T07:44:13","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=7371"},"modified":"2022-08-12T13:14:13","modified_gmt":"2022-08-12T07:44:13","slug":"generics-in-java","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/","title":{"rendered":"\u00a0GENERICS IN JAVA"},"content":{"rendered":"<p><strong>What are generics in java?<\/strong><\/p>\n<p>Generics is a term that denotes a set of language features related to the definition and use of generics types and methods.<\/p>\n<p><strong>Java generics<\/strong> programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code stable by detecting the bugs at compile time.<\/p>\n<p>Java generic methods differ from regular data types and methods so before generics we used collections to store any type of object it can be either generics or non-generic objects now generics force the java programmer to store a specific type of object.<\/p>\n<p><strong>Why java generics?<\/strong><\/p>\n<p>When the data type is not fixed it is integer or float then checked the data type and assigned the current data type.<\/p>\n<p><strong>Code that uses generics has many benefits over non-generic code:<\/strong><\/p>\n<ul>\n<li>Stronger type checks at compile time.<br \/>\nA Java compiler applies strong type checking to generic code and issues errors if the code violates type safety. Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find.<\/li>\n<\/ul>\n<p><strong>Elimination of casts.<\/strong><br \/>\nThe following code snippet without generics requires casting:<\/p>\n<pre class=\"lang:default decode:true\">List list = new ArrayList();\r\n\r\nlist.add(\"hello\");\r\n\r\nString s = (String) list.get(0);<\/pre>\n<p>When re-written to use generics, the code does not require casting:<\/p>\n<pre class=\"lang:default decode:true\">List&lt;String&gt; list = new ArrayList&lt;String&gt;();\r\n\r\nlist.add(\"hello\");\r\n\r\nString s = list.get(0);\u00a0\u00a0 \/\/ no cast<\/pre>\n<ul>\n<li>Enabling programmers to implement generic algorithms.<br \/>\nBy using generics, programmers can implement generic algorithms that work on collections of different types, can be customized, and are type-safe and easier to read.<\/li>\n<\/ul>\n<h4><strong>Type Parameters<\/strong><\/h4>\n<h4>The type parameters naming conventions are important to learn generics thoroughly. The common type parameters are as follows:<\/h4>\n<ol>\n<li><strong>T &#8211; Type<\/strong><\/li>\n<li><strong>E &#8211; Element<\/strong><\/li>\n<li><strong>K &#8211; Key<\/strong><\/li>\n<li><strong>N &#8211; Number<\/strong><\/li>\n<li><strong>V &#8211; Value<\/strong><\/li>\n<\/ol>\n<p><strong>Type of java generics:- <\/strong><\/p>\n<ol>\n<li><strong>Generic type class<\/strong><\/li>\n<li><strong>Generic Method<\/strong><\/li>\n<li><strong>Generic Interface <\/strong><\/li>\n<li><strong>Generic Constructor<\/strong><\/li>\n<\/ol>\n<ol>\n<li><strong> <u>Generics type class:-<\/u><\/strong><\/li>\n<\/ol>\n<p>A class is said generics if it declares one or more types of a variable so this variable is known as a parameter of the java class.<\/p>\n<p><strong>Let&#8217;s see a simple example to create and use the generic class.<\/strong><\/p>\n<p><strong>Ex:-<\/strong><\/p>\n<pre class=\"lang:default decode:true\">Class GenericClass{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Private object x;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Public void set(object x) { this.x = x;}\r\n\r\n\u00a0\u00a0 Public object get()\u00a0 { return x; }\r\n\r\n}<\/pre>\n<p>Let&#8217;s another example:-<\/p>\n<pre class=\"lang:default decode:true\">class MyGen&lt;T&gt;{\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 T obj;\u00a0\r\n\r\nvoid add(T obj){this.obj=obj;}\u00a0\r\n\r\nT get(){return obj;}\u00a0\r\n\r\n}<\/pre>\n<p>The T type indicates that it can refer to any type (like String, Integer, and Employee). The type you specify for the class will be used to store and retrieve the data.<\/p>\n<ol start=\"2\">\n<li><strong> Generic Method:-<\/strong><\/li>\n<\/ol>\n<p>We can write a single generic method declaration that can be called with arguments of different types.<\/p>\n<p><strong>EX:-<\/strong><\/p>\n<pre class=\"lang:default decode:true\">Public class Example{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Public &lt;E&gt; void printArrayElement( E a[]){\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for(E x : a ){\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0System.out. println(\u201c \u201d + x);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0 }\r\n\r\npublic static void main( String[] args)\r\n\r\n{\r\n\r\n\u00a0 Example e1=new Example();\r\n\r\n\u00a0 String s[]= new String[]; {\u201cIndia\u201d,\u201dPakistan\u201d,\u201dNepal\u201d}\r\n\r\ne1.printArrayElement(s);\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>IMPORTANT POINT:-<\/strong><\/p>\n<p>All generic method declarations have a type parameter section delimited by angle brackets (&lt;&gt;) that precedence the method&#8217;s return type.<\/p>\n<ul>\n<li>Each type of parameter section contains one or more type parameters separated by commas.<\/li>\n<li>The type parameters can be used to declare the return type.<\/li>\n<li>Type parameter can represent only reference type not primitive type (like int, double, and char)<\/li>\n<\/ul>\n<ol start=\"3\">\n<li><strong> Generic Interface:-<\/strong><\/li>\n<\/ol>\n<pre class=\"lang:default decode:true \">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Generics also work with interfaces. Thus, you can also have generic interfaces. Generic interfaces are specified just like generic classes. For example :\r\n\r\ninterface MyInterface&lt;T&gt; (\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 void myMethod (T t);\u00a0\u00a0\u00a0\u00a0 \u2014--------&gt;Generic Interface\r\n\r\n}\r\n\r\nclass Myclass implements MyInterface&lt;Integer&gt; {\u00a0\u00a0\r\n\r\npublic void myMethod (Integer 1) {\r\n\r\nSystem.out.println(\"MyMethod -&gt; 1-&gt; \"+1);\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>The <strong>MyInterface<\/strong> is a generic interface that declares the method called <strong>myMethod( )<\/strong>. In general, a generic interface is declared in the same way as a generic class. In this case, the type parameter is <strong>T<\/strong>. Next, <strong>MyClass implements MyInterface<\/strong>. <strong>Myclass<\/strong> is a non-generic class. Of course, if a class implements a specific type of generic interface, then the implementing class does not need to be generic.<\/p>\n<p>We can create generic interfaces in java. We can also have multiple types of parameters as in the map interface. Again we can provide parameterized value to a parameterized type also.<\/p>\n<p><strong>\u00a0For Example:-<\/strong><\/p>\n<p>New HashMap&lt;String, List&lt;String &gt;&gt;(); is valid.<\/p>\n<ol start=\"4\">\n<li><strong>Generic Constructor:-<\/strong><\/li>\n<\/ol>\n<p>Generic constructors are the same as generic methods. For generic constructors after the public keyword and before the class name the type parameter must be placed.\u00a0 Constructors can be invoked with any type of parameter after defining a generic constructor. A constructor is a block of code that initializes the newly created object. It is an instance method with no return type. The name of the constructor is the same as the class name. Constructors can be Generic, despite their class is not Generic.<\/p>\n<p><strong>Example:-<\/strong>\/\/ Java Program to illustrate Generic constructors<\/p>\n<pre class=\"lang:default decode:true \">import java.io.*;\r\n\r\nclass GenericConstructor {\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 private double v;\r\n\r\n\r\n\r\n\r\n&lt;T extends Number&gt; GenericConstructor(T t)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 v = t.doubleValue();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 void show()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"v: \" + v);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n}\r\n\r\n\r\n\r\n\r\nclass Main {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static void main(String[] args)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Number to Double Conversion:\");\r\n\r\nGenericConstructor obj1\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = new GenericConstructor(10);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GenericConstructor obj2\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = new GenericConstructor(136.8F);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 obj1.show();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 obj2.show();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n}<\/pre>\n<p><strong>Output:-<\/strong><\/p>\n<p><strong>Number to Double Conversion:<\/strong><\/p>\n<p><strong>v: 10.0<\/strong><\/p>\n<p><strong>v: 136.8000030517578<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are generics in java? Generics is a term that denotes a set of language features related to the definition and use of generics types and methods. Java generics programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code stable by detecting the bugs at compile time. Java generic methods [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7372,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256,360],"tags":[722,793,795,224,794],"class_list":["post-7371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-application","category-javascript","tag-blog","tag-generics","tag-generics-in-java","tag-java","tag-java-generics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u00a0GENERICS IN JAVA - InnovationM - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/generics-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u00a0GENERICS IN JAVA - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"What are generics in java? Generics is a term that denotes a set of language features related to the definition and use of generics types and methods. Java generics programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code stable by detecting the bugs at compile time. Java generic methods [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/generics-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-12T07:44:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2022\/08\/Generics-in-Java.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1689\" \/>\n\t<meta property=\"og:image:height\" content=\"950\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"\u00a0GENERICS IN JAVA\",\"datePublished\":\"2022-08-12T07:44:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/\"},\"wordCount\":665,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Generics-in-Java.png\",\"keywords\":[\"blog\",\"generics\",\"generics in java\",\"java\",\"java generics\"],\"articleSection\":[\"Java Application\",\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/\",\"name\":\"\u00a0GENERICS IN JAVA - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Generics-in-Java.png\",\"datePublished\":\"2022-08-12T07:44:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Generics-in-Java.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Generics-in-Java.png\",\"width\":1689,\"height\":950},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/generics-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u00a0GENERICS IN JAVA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u00a0GENERICS IN JAVA - InnovationM - Blog","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:\/\/www.innovationm.com\/blog\/generics-in-java\/","og_locale":"en_US","og_type":"article","og_title":"\u00a0GENERICS IN JAVA - InnovationM - Blog","og_description":"What are generics in java? Generics is a term that denotes a set of language features related to the definition and use of generics types and methods. Java generics programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code stable by detecting the bugs at compile time. Java generic methods [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/","og_site_name":"InnovationM - Blog","article_published_time":"2022-08-12T07:44:13+00:00","og_image":[{"width":1689,"height":950,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2022\/08\/Generics-in-Java.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"\u00a0GENERICS IN JAVA","datePublished":"2022-08-12T07:44:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/"},"wordCount":665,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2022\/08\/Generics-in-Java.png","keywords":["blog","generics","generics in java","java","java generics"],"articleSection":["Java Application","JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/generics-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/","url":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/","name":"\u00a0GENERICS IN JAVA - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2022\/08\/Generics-in-Java.png","datePublished":"2022-08-12T07:44:13+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/generics-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2022\/08\/Generics-in-Java.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2022\/08\/Generics-in-Java.png","width":1689,"height":950},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/generics-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"\u00a0GENERICS IN JAVA"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/7371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=7371"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/7371\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/7372"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=7371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=7371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=7371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}