{"id":31,"date":"2014-05-26T12:06:23","date_gmt":"2014-05-26T12:06:23","guid":{"rendered":"http:\/\/vkrastev1blog.com\/?p=31"},"modified":"2014-05-26T15:36:27","modified_gmt":"2014-05-26T15:36:27","slug":"java-generics-explained-in-short-form-with-examples","status":"publish","type":"post","link":"https:\/\/vkrastev1blog.com\/2014\/05\/26\/java-generics-explained-in-short-form-with-examples\/","title":{"rendered":"Java generics explained in short form with examples"},"content":{"rendered":"<p>Please see this FAQ for more information:<\/p>\n<p><a href=\"http:\/\/www.angelikalanger.com\/GenericsFAQ\/JavaGenericsFAQ.html#SECTION1\" rel=\"nofollow\">http:\/\/www.angelikalanger.com\/GenericsFAQ\/JavaGenericsFAQ.html#SECTION1<\/a><\/p>\n<p>Here in short form some important points from this FAQ.<\/p>\n<p>Example (of a generic type):<\/p>\n<blockquote><p><tt> class Pair&lt;X,Y&gt; {\u00a0<\/tt><br \/>\n<tt> \u00a0 private X first;<\/tt><br \/>\n<tt> \u00a0 private Y second;<\/tt><tt> \u00a0 public Pair(X a1, Y a2) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 first = a1;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 second = a2;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public X getFirst() { return first; }<\/tt><br \/>\n<tt> \u00a0 public Y getSecond() { return second; }<\/tt><br \/>\n<tt> \u00a0 public void setFirst(X arg)\u00a0 { first = arg; }<\/tt><br \/>\n<tt> \u00a0 public void setSecond(Y arg) { second = arg; }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The class <tt> Pair<\/tt> has two type parameters <tt> X <\/tt> and <tt> Y<\/tt> .\u00a0 They are replaced by type arguments when the generic type <tt> Pair<\/tt> is instantiated. For instance, in the declaration <tt> Pair&lt;String, Date&gt;<\/tt> the type parameter <tt> X<\/tt> is replaced by the type argument <tt> String<\/tt> and <tt> Y<\/tt> is replaced by\u00a0 <tt> Date<\/tt> .<br \/>\nThe scope of the identifiers <tt> X <\/tt> and <tt> Y<\/tt> is<b> <i> <\/i> <\/b> the entire definition of the class.\u00a0 In this scope the two type parameters <tt> X <\/tt> and <tt> Y<\/tt> are used like they were types (with some restrictions). In the example above, the type parameters are used as the argument and return type of instance methods and the types of instance fields.<br \/>\nType parameters can be declared with bounds. Bounds give access to methods of the unknown type that the type parameter stands for. In our example, we do not invoke any methods of the unknown types <tt> X <\/tt> and <tt> Y<\/tt> . For this reason, the two type parameters are unbounded.<\/p>\n<p>Example (of a concrete parameterized type):<\/p>\n<blockquote><p><tt> public void printPair(<b> <span style=\"color:#000099;\"> Pair&lt;String,Long&gt;<\/span> <\/b> pair) {<\/tt><br \/>\n<tt> \u00a0 System.out.println(\"(\"+pair.getFirst()+\",\"+pair.getSecond()+\")\");<\/tt><br \/>\n<tt> }<\/tt><tt> <b> <span style=\"color:#000099;\"> Pair&lt;String,Long&gt;<\/span> <\/b> limit = new <b> <span style=\"color:#000099;\"> Pair&lt;String,Long&gt;<\/span> <\/b> (\"maximum\",1024L);<\/tt><br \/>\n<tt> printPair(limit);<\/tt><\/p><\/blockquote>\n<p>Example (of a wildcard parameterized type):<\/p>\n<blockquote>\n<blockquote><p><tt> public void printPair(<b> <span style=\"color:#000099;\"> Pair&lt;?,?&gt;<\/span> <\/b> pair) {<\/tt><br \/>\n<tt> \u00a0 System.out.println(\"(\"+pair.getFirst()+\",\"+pair.getSecond()+\")\");<\/tt><br \/>\n<tt> }<\/tt><tt> <b> <span style=\"color:#000099;\"> Pair&lt;?,?&gt;<\/span> <\/b> limit = new <b> <span style=\"color:#000099;\"> Pair&lt;String,Long&gt;<\/span> <\/b> (\"maximum\",1024L);<\/tt><br \/>\n<tt> printPair(limit);<\/tt><\/p><\/blockquote>\n<\/blockquote>\n<p>All instantiations of a generic type share the same runtime type representation, namely the representation of the raw type. For instance, the instantiations of a generic type <tt> List<\/tt> , such as <tt> List&lt;Date&gt;<\/tt> , <tt> List&lt;String&gt;<\/tt> , <tt> List&lt;Long&gt;<\/tt> , etc. have different static types at compile time, but the same dynamic type <tt> List <\/tt> at runtime.<\/p>\n<p>A cast consists of two parts:<\/p>\n<ul>\n<li>a static type check performed by the compiler at compile time and<\/li>\n<li>a dynamic type check performed by the virtual machine at runtime.<\/li>\n<\/ul>\n<p>The static part sorts out nonsensical casts, that cannot succeed, such as the cast from <tt> String<\/tt> that <tt> Date<\/tt> or from <tt> List&lt;String&gt;<\/tt> that <tt> List&lt;Date&gt;<\/tt> .<\/p>\n<p>The dynamic part uses the runtime type information and performs a type check at runtime.\u00a0 It raises a <tt> ClassCastException<\/tt> if the dynamic type of the object is not the target type (or a subtype of the target type) of the cast. Examples of casts with a dynamic part are the cast from <tt> Object<\/tt> that <tt> String<\/tt> or from <tt> Object<\/tt> that <tt> List&lt;String&gt;<\/tt> .\u00a0 These are the so-called downcasts, from a supertype down to a subtype.<\/p>\n<p>Examples of concrete parameterized types are <tt> List&lt;String&gt;<\/tt> , <tt> Map&lt;String,Date&gt;<\/tt> , but not <tt> List&lt;? extends Number&gt;<\/tt> or <tt> Map&lt;String,?&gt;<\/tt> .<\/p>\n<p>It is sometimes expected that a <tt> List&lt;Object&gt;<\/tt> would be a supertype of a <tt> List&lt;String&gt;<\/tt> , because <tt> Object<\/tt> is a supertype of <tt> String<\/tt> .\u00a0 This expectation stems from the fact that such a type of relationship exists for arrays:\u00a0 <tt> Object[]<\/tt> is a supertype of <tt> String[]<\/tt> , because <tt> Object<\/tt> is a supertype of <tt> String<\/tt> . (This type of relationship is known as <i> covariance<\/i> .) The super-subtype-relationship of the component types extends into the corresponding array types. No such a type relationship exists for instantiations of generic types. (Parameterized types are <i> not<\/i> covariant.)<\/p>\n<p>The lack of a super-subtype-relationship among instantiations of the same generic type has various consequences.\u00a0 Here is an example.<\/p>\n<p>Example:<\/p>\n<p><tt> void printAll(ArrayList&lt;Object&gt; c) {<\/tt><br \/>\n<tt> \u00a0 for (Object o : c)\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 System.out.println(o);<\/tt><br \/>\n<tt> }<\/tt><tt> ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();<\/tt><br \/>\n<tt> ... fill list ...<\/tt><br \/>\n<tt> printAll(list);\u00a0\u00a0 \/\/ error<\/tt><\/p>\n<p>A <tt> ArrayList&lt;String&gt;<\/tt> object cannot be passed as argument to a method that asks for a <tt> ArrayList&lt;Object&gt;<\/tt> because the two types are instantiations of the same generic type, but for <i> different<\/i> type arguments, and for this reason they are not compatible with each other.<\/p>\n<p>Concrete parameterized types are concrete instantiations of a generic type.\u00a0 They are almost like types; there are only a few restrictions.\u00a0 They can NOT be used for the following purposes:<\/p>\n<ul>\n<li>for creation of arrays<\/li>\n<li>in exception handling<\/li>\n<li>in a class literal<\/li>\n<li>in an <tt> instanceof<\/tt> expression<\/li>\n<\/ul>\n<p>Arrays holding elements whose type is a concrete parameterized type are illegal.<\/p>\n<p>Example (of illegal array type):<\/p>\n<p><tt> static void test() {<\/tt><br \/>\n<tt> \u00a0 <b> <span style=\"color:#660000;\"> Pair&lt;Integer,Integer&gt;[]<\/span> <\/b> intPairArr = new <b> <span style=\"color:#660000;\"> Pair&lt;Integer,Integer&gt;[10]<\/span> <\/b> ; <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 addElements(intPairArr);\u00a0<\/tt><br \/>\n<tt> \u00a0 Pair&lt;Integer,Integer&gt; pair = intPairArr[1];<\/tt><br \/>\n<tt> \u00a0 Integer i = pair.getFirst();<\/tt><br \/>\n<tt> \u00a0 pair.setSecond(i);<\/tt><br \/>\n<tt> }<\/tt><br \/>\n<tt> static void addElements(<b> Object[]<\/b> objArr) {<\/tt><br \/>\n<tt> \u00a0 objArr[0] = new Pair&lt;Integer,Integer&gt;(0,0);<\/tt><br \/>\n<tt> \u00a0 objArr[1] = new Pair&lt;String,String&gt;(\"\",\"\");\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ should fail with ArrayStoreException<\/tt><br \/>\n<tt> }<\/tt><\/p>\n<p>The compiler prohibits creation of arrays whose component type is a concrete parameterized type, like <tt> Pair&lt;Integer,Integer&gt;<\/tt> in our example.\u00a0 We discussed in the preceding entry why it is reasonable that the compiler qualifies a<span style=\"color:#000000;\"> <tt> Pair&lt;Integer,Integer&gt;[]<\/tt> <\/span> as illegal.\u00a0 The key problem is that the compiler and runtime system must ensure that an array is a <i> homogeneous<\/i> sequence of elements of the same type.\u00a0 One of the type checks, namely the array-store-check performed by the virtual machine at runtime, fails to detect the offending insertion of an alien element. In the example the second insertion in the <tt> addElements<\/tt> method should fail, because they were adding a pair of strings to an array of integral values, but it does not fail as expected. The reasons were discussed in the preceding entry.<\/p>\n<p>If we cannot use arrays holding elements whose type is a concrete parameterized type, what do we use as a workaround?<\/p>\n<p>Let us consider 3 conceivable workarounds:<\/p>\n<ul>\n<li>array of raw types<\/li>\n<li>array of unbounded wildcard parameterized type<\/li>\n<li>collection instead of array<\/li>\n<\/ul>\n<p>While arrays of concrete parameterized types are illegal, collections of concrete parameterized types are permitted.<\/p>\n<p>A wildcard parameterized type is an instantiation of a generic type where at least one type argument is a wildcard.\u00a0 Examples of wildcard parameterized types are <tt> Collection&lt;?&gt;<\/tt> , <tt> List&lt;? extends Number&gt;<\/tt> , <tt> Comparator&lt;? super String&gt;<\/tt> and <tt> Pair&lt;String,?&gt;<\/tt> . A wildcard parameterized type denotes a family of types comprising concrete instantiations of a generic type.\u00a0 The kind of the wildcard being used determines which concrete parameterized types belong to the family.\u00a0 For instance, the wildcard parameterized type <tt> Collection&lt;?&gt;<\/tt> denotes the family of all instantiations of the <tt> Collection<\/tt> interface regardless of the type argument.\u00a0 The wildcard parameterized type <tt> List&lt;? extends Number&gt;<\/tt> denotes the family of all list types where the element type is a subtype of\u00a0 <tt> Number<\/tt> .\u00a0 The wildcard parameterized type <tt> Comparator&lt;? super String&gt;<\/tt> is the family of all instantiations of the <tt> Comparator<\/tt> interface for type argument types that are supertypes of <tt> String.<\/tt><\/p>\n<p><strong><em>A wildcard parameterized type is not a type in the regular sense (different from a non-parameterized class\/interface or a raw type).<\/em> <\/strong><\/p>\n<p>Wildcard parameterized types can be used for typing (like non-parameterized classes and interfaces):<\/p>\n<ul>\n<li>as argument and return types of methods<\/li>\n<li>as type of a field or local reference variable<\/li>\n<li>as component type of an arrayas type argument of other parameterized types<\/li>\n<li>as target type in casts<\/li>\n<\/ul>\n<p>Not only types can be generic, but methods can be generic, too. Static and non-static methods as well as constructors can have type parameters. The syntax for declaration of the formal type parameters is similar to the syntax for generic types. The type parameter section is delimited by angle brackets and appears before the method&#8217;s return type. Its syntax and meaning is identical to the type parameter list of a generic type.<\/p>\n<p>Here is the example of a generic <tt> max<\/tt> method that computes the greatest value in a collection of elements of an unknown type <tt> A<\/tt> .<\/p>\n<p>Example (of a generic method):<\/p>\n<blockquote><p><tt> class Collections {<\/tt><br \/>\n<tt> \u00a0 public static <b> <span style=\"color:#000099;\"> &lt;A extends Comparable&lt;A&gt;&gt; A<\/span> <\/b> max(Collection&lt;<b> <span style=\"color:#000099;\"> A<\/span> <\/b> &gt; xs) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 Iterator&lt;<b> <span style=\"color:#000099;\"> A<\/span> <\/b> &gt; xi = xs.iterator();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 <b> <span style=\"color:#000099;\"> A<\/span> <\/b> w = xi.next();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 while (xi.hasNext()) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#000099;\"> A<\/span> <\/b> x = xi.next();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 if (w.compareTo(x) &lt; 0) w = x;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 return w;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }\u00a0<\/tt><\/p><\/blockquote>\n<p>The <tt> max<\/tt> method has one type parameter, named<tt> A<\/tt> .\u00a0 It is a place holder for the element type of the collection that the method works on. The type parameter has a bound; it must be a type that is a subtype of <tt> Comparable&lt;A&gt;<\/tt><\/p>\n<p>Example (of the same generic type, this time <i> with<\/i> bounds):<\/p>\n<blockquote><p><tt> public interface Comparable&lt;T&gt; {<\/tt><br \/>\n<tt> \u00a0 public int compareTo(T arg);<\/tt><br \/>\n<tt> }<\/tt><br \/>\n<tt> public class TreeMap&lt;Key <b> <span style=\"color:#000066;\"> extends Comparable&lt;Key&gt;<\/span> <\/b> ,Data&gt;{<\/tt><br \/>\n<tt> \u00a0 private static class Entry&lt;K,V&gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 K key;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 V value;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Entry&lt;K,V&gt; left = null;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Entry&lt;K,V&gt; right = null;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Entry&lt;K,V&gt; parent;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private transient Entry&lt;Key,Data&gt; root = null;<\/tt><br \/>\n<tt> \u00a0 ...<\/tt><br \/>\n<tt> \u00a0 private Entry&lt;Key,Data&gt; getEntry(Key key) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Entry&lt;Key,Data&gt; p = root;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Key k = key;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 while (p != null) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int cmp = k.<b> <span style=\"color:#990000;\"> compareTo(p.key)<\/span> <\/b> ;\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (cmp == 0)<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return p;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else if (cmp &lt; 0)<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 p = p.left;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 p = p.right;\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 return null;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public boolean containsKey(Key key) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 return getEntry(key) != null;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 ...<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>In the example above, the type parameter <tt> Key<\/tt> has the bound <tt> Comparable&lt;Key&gt;<\/tt> .\u00a0 Specification of a bound has two effects:<\/p>\n<ul>\n<li><i> It gives access to the methods that the bound specifies<\/i> .\u00a0 In the example, the bound <tt> Comparable&lt;Key&gt; <\/tt> gives access to the <tt> compareTo<\/tt> method that we want to invoke in the implementation of our <tt> TreeMap<\/tt> class.<\/li>\n<\/ul>\n<ul>\n<li><i> Only types &#8220;within bounds&#8221; can be used for instantiation of the generic type.<\/i> \u00a0 In the example, a parameterized type such as <tt> TreeMap&lt;Number,String&gt;<\/tt> would be rejected, because the type <tt> Number<\/tt> is not a subtype of <tt> Comparable&lt;Number&gt;<\/tt> .\u00a0 A parameterized type like <tt> TreeMap&lt;String,String&gt;<\/tt> would be accepted, because the type String is within bounds, i.e. is a subtype of <tt> Comparable&lt;String&gt;<\/tt> .<\/li>\n<\/ul>\n<p>All classes, interfaces, and enum types can be used as type parameter bound, including nested and inner types.\u00a0 Neither primitive types nor array types be used as type parameter bound.<\/p>\n<p>Examples (of type parameter bounds):<\/p>\n<blockquote><p><tt> class X0 &lt;T extends <b> <span style=\"color:#000099;\"> int<\/span> <\/b> &gt; { ... }\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> class X1 &lt;T extends <b> <span style=\"color:#000099;\"> Object[]<\/span> <\/b> &gt; { ... } <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> class X2 &lt;T extends <b> <span style=\"color:#000099;\"> Number<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X3 &lt;T extends <b> <span style=\"color:#000099;\"> String<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X4 &lt;T extends <b> <span style=\"color:#000099;\"> Runnable<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X5 &lt;T extends <b> <span style=\"color:#000099;\"> Thread.State<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X6 &lt;T extends <b> <span style=\"color:#000099;\"> List<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X7 &lt;T extends <b> <span style=\"color:#000099;\"> List&lt;String&gt;<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X8 &lt;T extends <b> <span style=\"color:#000099;\"> List&lt;? extends Number&gt;<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X9 &lt;T extends <b> <span style=\"color:#000099;\"> Comparable&lt;? super Number&gt;<\/span> <\/b> &gt; { ... }<\/tt><br \/>\n<tt> class X10&lt;T extends <b> <span style=\"color:#000099;\"> Map.Entry&lt;?,?&gt;<\/span> <\/b> &gt; { ... }<\/tt><\/p><\/blockquote>\n<p>The code sample shows that primitive types such as <tt> int<\/tt> and array types such as <tt> Object[] <\/tt> are not permitted as type parameter bound.<\/p>\n<p>Class types, such as <tt> Number<\/tt> or <tt> String<\/tt> , and interface types, such as <tt> Runnable<\/tt> , are permitted as type parameter bound.<\/p>\n<p>Enum types, such as <tt> Thread.State<\/tt> are also permitted as type parameter bound. <tt> Thread.State<\/tt> is an example of a nested type used as type parameter bound.\u00a0 Non-static inner types are also permitted.<\/p>\n<p>Raw types are permitted as type parameter bound; <tt> <span style=\"color:#000000;\"> List<\/span> <\/tt> is an example.<\/p>\n<p>Parameterized types are permitted as type parameter bound, including concrete parameterized types such as <tt> List&lt;String&gt;<\/tt> , bounded wildcard parameterized types such as <tt> List&lt;? extends Number&gt;<\/tt> and <tt> Comparable&lt;? super Long&gt;<\/tt> , and unbounded wildcard parameterized types such as <tt> Map.Entry&lt;?,?&gt;<\/tt> .\u00a0 A bound that is a wildcard parameterized type allows as type argument all types that belong to the type family that the wildcard denotes.\u00a0 The wildcard parameterized type bound gives only restricted access to fields and methods; the restrictions depend on the kind of wildcard.<\/p>\n<p>Example (of wildcard parameterized type as type parameter bound):<\/p>\n<blockquote><p><tt> class X&lt;<b> <span style=\"color:#000099;\"> T extends List&lt;? extends Number&gt;<\/span> <\/b> &gt; {<\/tt><br \/>\n<tt> \u00a0 public void someMethod(T t) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 t.add(new Long(0L));\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 Number n = t.remove(0);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><br \/>\n<tt> class Test {<\/tt><br \/>\n<tt> \u00a0 public static void main(String[] args) {<\/tt><br \/>\n<tt> <b> <span style=\"color:#660000;\"> \u00a0\u00a0\u00a0\u00a0 <\/span> <\/b> <span style=\"color:#000000;\"> X&lt;ArrayList&lt;<\/span> <b> <span style=\"color:#000099;\"> Long<\/span> <\/b> <span style=\"color:#000000;\"> &gt;&gt; x1 = new X&lt;ArrayList&lt;Long&gt;&gt;();\u00a0<\/span> <\/tt><br \/>\n<tt> <span style=\"color:#000000;\"> \u00a0\u00a0\u00a0\u00a0 X&lt;ArrayList&lt;<\/span> <b> <span style=\"color:#000099;\"> String<\/span> <\/b> <span style=\"color:#000000;\"> &gt;&gt; x2 = new X&lt;ArrayList&lt;String&gt;&gt;(); <\/span> <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>Reference variables of type<tt> T <\/tt> (the type parameter) are treated like reference variables of a wildcard type (the type parameter bound).\u00a0 In our example the consequence is that the compiler rejects invocation of methods that take an argument of the &#8220;unknown&#8221; type that the type parameter stands for, such as <tt> List.add<\/tt> , because the bound is a wildcard parameterized type with an upper bound.<br \/>\nAt the same time the bound <tt> List&lt;? extends Number&gt;<\/tt> determines the types that can be used as type arguments. The compiler accepts all type arguments that belong to the type family <tt> List&lt;? extends Number&gt;<\/tt> , that is, all subtypes of <tt> List<\/tt> with a type argument that is a subtype of <tt> Number<\/tt> .<\/p>\n<p>A type parameter can be used as the bound of another type parameter.<\/p>\n<p>Example (of a type parameter used as a type parameter bound):<\/p>\n<blockquote><p><tt> class Triple<b> &lt;T&gt;<\/b> {<\/tt><br \/>\n<tt> \u00a0 private T fst, snd, trd;<\/tt><br \/>\n<tt> \u00a0 public &lt;<b> U<\/b> <b> <span style=\"color:#000099;\"> extends T<\/span> <\/b> , <b> V <span style=\"color:#000099;\"> extends T<\/span> <\/b> , <b> W <span style=\"color:#000099;\"> extends T<\/span> <\/b> &gt; Triple(U arg1, V arg2, W arg3) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 fst = arg1;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 snd = arg2;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 trd = arg3;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>In this example the type parameter <tt> T<\/tt> of the parameterized class is used as bound of the type parameters <tt> U<\/tt> ,\u00a0 <tt> V<\/tt> and <tt> W<\/tt> of a parameterized instance method of that class.<\/p>\n<p>Further opportunities for using type parameters as bounds of other type parameters include situations where a nested type is defined inside a generic type or a local class is defined inside a generic method.\u00a0 It is even permitted to use a type parameter as bound of another type parameter in the same type parameter section.<\/p>\n<p>A bound that is a class gives access to all its public members, that is, public fields, methods, and nested types. Only constructors are not made accessible, because there is no guarantee that a subclass of the bound has the same constructors as the bound.<\/p>\n<p>Example (of a class used as bound of a type parameter):<\/p>\n<blockquote><p><tt> public class <span style=\"color:#000000;\"> SuperClass<\/span> {<\/tt><tt> \u00a0\u00a0\u00a0 \/\/ static members<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public enum EnumType {THIS, THAT}<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public static Object staticField;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public static void staticMethod() { ... }<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0 \/\/ non-static members<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public class InnerClass { ... }<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public Object nonStaticField;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public void nonStaticMethod() { ... }<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0 \/\/ constructors<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public SuperClass() { ... }<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0 \/\/ private members<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 private Object privateField;\u00a0<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0 ...<\/tt><br \/>\n<tt> }<\/tt><\/p>\n<p><tt> public final class SomeClass&lt;T extends <b> <span style=\"color:#006600;\"> SuperClass<\/span> <\/b> &gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 private T object;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public SomeClass(T t) { object = t; }\u00a0<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0 public String toString() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"static nested type\u00a0\u00a0\u00a0 : \"+T.EnumType.class+\"\\n\"\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"static field\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \"+T.staticField+\"\\n\"<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"static method\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \"+T.staticMethod()+\"\\n\"<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"non-static nested type: \"+T.InnerClass.class+\"\\n\"<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"non-static field\u00a0\u00a0\u00a0\u00a0\u00a0 : \"+object.nonStaticField+\"\\n\"<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"non-static method\u00a0\u00a0\u00a0\u00a0 : \"+object.nonStaticMethod()+\"\\n\"<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"constructor\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \"+(new T())+\"\\n\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ error<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 +\"private member\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \"+object.privateField+\"\\n\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ error\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The bound <tt> SuperClass<\/tt> gives access to its nested types, static fields and methods and non-static fields and methods.\u00a0 Only the constructor is not accessible.\u00a0 This is because constructors are not inherited. Each subclass defines its own constructors and need not support its superclass&#8217;s constructors.\u00a0 Hence there is no guarantee that a subclass of <tt> SuperClass<\/tt> will have the same constructor as its superclass.<\/p>\n<p>The context in which<tt> Enum&lt;E extends Enum&lt;E&gt;&gt;<\/tt> &#8221; appears is the declaration of the <tt> Enum<\/tt> class in package <tt> java.lang<\/tt> :<\/p>\n<blockquote><p><tt> public abstract class <b> Enum&lt;E extends Enum&lt;E&gt;&gt;<\/b> {<\/tt><br \/>\n<tt> \u00a0 ...<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The type <tt> Enum<\/tt> is the common base class of all enumeration types.\u00a0 In Java an enumeration type such as <tt> Color<\/tt> is translated into a class <tt> Color<\/tt> that extends <tt> Enum&lt;Color&gt;<\/tt> . The purpose of the superclass <tt> Enum<\/tt> is to provide functionality that is common to all enumeration types.<\/p>\n<p>Here is a sketch of class <tt> Enum<\/tt> :<\/p>\n<blockquote><p><tt> public abstract class <b> Enum&lt;<span style=\"color:#000099;\"> E<\/span> extends Enum&lt;E&gt;&gt;<\/b> implements Comparable&lt;<b> <span style=\"color:#000099;\"> E<\/span> <\/b> &gt;, Serializable {<\/tt><br \/>\n<tt> \u00a0 private final String name;<\/tt><br \/>\n<tt> \u00a0 public final String name() { ... }<\/tt><tt> \u00a0 private final int ordinal;<\/tt><br \/>\n<tt> \u00a0 public final int ordinal() { ... }<\/tt><\/p>\n<p><tt> \u00a0 protected Enum(String name, int ordinal) { ... }<\/tt><\/p>\n<p><tt> \u00a0 public String\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 toString() { ... }<\/tt><br \/>\n<tt> \u00a0 public final boolean equals(Object other) { ... }<\/tt><br \/>\n<tt> \u00a0 public final int hashCode() { ... }<\/tt><br \/>\n<tt> \u00a0 protected final Object clone() throws CloneNotSupportedException { ... }<\/tt><br \/>\n<tt> \u00a0 public final int compareTo(<b> <span style=\"color:#000099;\"> E<\/span> <\/b> o) { ... }<\/tt><\/p>\n<p><tt> \u00a0 public final Class&lt;<b> <span style=\"color:#000099;\"> E<\/span> <\/b> &gt; getDeclaringClass() { ... }<\/tt><br \/>\n<tt> \u00a0 public static &lt;T extends Enum&lt;T&gt;&gt; T valueOf(Class&lt;T&gt; enumType, String name) { ... }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The surprising feature in the declaration &#8220;<tt> Enum&lt;E extends Enum&lt;E&gt;&gt;<\/tt> &#8221; is the fact that the newly defined class <tt> Enum<\/tt> and its newly defined type parameter <tt> E <\/tt> appear in the bound of that same type parameter.\u00a0 It means that the <tt> Enum<\/tt> type must be instantiated for one of its subtypes.\u00a0 In order to understand why this makes sense, consider that every enum type is translated into a subtype of <tt> Enum<\/tt> .<\/p>\n<p>Here is the contrived enum type <tt> Color<\/tt> :<\/p>\n<blockquote><p><tt> enum <b> Color<\/b> {RED, BLUE, GREEN}<\/tt><\/p><\/blockquote>\n<p>The compiler translates it into the following class:<\/p>\n<blockquote><p><tt> public final class <b> Color<\/b> extends <b> Enum&lt;Color&gt;<\/b> {<\/tt><br \/>\n<tt> \u00a0 public static final Color[] values() { return (Color[])$VALUES.clone(); }<\/tt><br \/>\n<tt> \u00a0 public static Color valueOf(String name) { ... }<\/tt><tt> \u00a0 private Color(String s, int i) { super(s, i); }<\/tt><\/p>\n<p><tt> \u00a0 public static final Color RED;<\/tt><br \/>\n<tt> \u00a0 public static final Color BLUE;<\/tt><br \/>\n<tt> \u00a0 public static final Color GREEN;<\/tt><\/p>\n<p><tt> \u00a0 private static final Color $VALUES[];<\/tt><\/p>\n<p><tt> \u00a0 static {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 RED = new Color(\"RED\", 0);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 BLUE = new Color(\"BLUE\", 1);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 GREEN = new Color(\"GREEN\", 2);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 $VALUES = (new Color[] { RED, BLUE, GREEN });<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The inheritance has the effect that the <tt> Color<\/tt> type inherits all the methods implemented in <tt> Enum&lt;Color&gt;<\/tt> .\u00a0 Among them is the <tt> compareTo<\/tt> method.\u00a0 The <tt> Color. compareTo<\/tt> method should probably take a <tt> Color<\/tt> as an argument.\u00a0 In order to make this happen class <tt> Enum<\/tt> is generic and the <tt> Enum.compareTo<\/tt> method takes <tt> Enum<\/tt> &#8216;s type parameter <tt> E <\/tt> as an argument.\u00a0 As a result, type <tt> Color<\/tt> derived from <tt> Enum&lt;Color&gt;<\/tt> inherits a <tt> compareTo<\/tt> method that takes a <tt> Color<\/tt> as and argument, exactly as it should.<br \/>\nIf we dissect the declaration &#8220;<tt> Enum&lt;E extends Enum&lt;E&gt;&gt;<\/tt> &#8221; we can see that this pattern has several aspects.<\/p>\n<p>First, there is the fact that the type parameter bound is the type itself: &#8220;<tt> <b> Enum<\/b> &lt;E extends <b> Enum<\/b> &lt;E&gt;&gt;<\/tt> &#8220;. It makes sure that only subtypes of type <tt> Enum<\/tt> are permitted as type arguments. (Theoretically, type <tt> Enum<\/tt> could be instantiated on itself, like in <tt> Enum&lt;Enum&gt;<\/tt> , but this is certainly not intended and it is hard to imagine a situation in which such an instantiation would be useful.)<\/p>\n<p>Second, there is the fact that the parameter bound type is the parameterized type <tt> Enum<b> &lt;E&gt;<\/b> <\/tt> , which uses the type parameter <tt> E<\/tt> as the type argument of the bound. This declaration makes sure that the inheritance relationship between a subtype and an instantiation of <tt> Enum<\/tt> is of the form<tt> X extends Enum&lt;X&gt;<\/tt> &#8220;. A subtype such as &#8220;<tt> X extends Enum&lt;Y&gt;<\/tt> &#8221; cannot be declared because of the type argument <tt> Y<\/tt> would not be within bounds; only subtypes of <tt> Enum&lt;X&gt;<\/tt> are within bounds.<\/p>\n<p>Third, there is the fact that <tt> Enum<\/tt> is generic in the first place.\u00a0 It means that some of the methods of class <tt> Enum<\/tt> take an argument or return a value of an unknown type (or otherwise depend on an unknown type). As we already know, this unknown type will later be a subtype <tt> X<\/tt> of <tt> Enum&lt;X&gt;<\/tt> .\u00a0 Hence, in the parameterized type <tt> Enum&lt;X&gt;<\/tt> , these methods involve the subtype <tt> X<\/tt> , and they are inherited into the subtype <tt> X<\/tt> .\u00a0 The <tt> compareTo<\/tt> method is an example of such a method; it is inherited from the superclass into each subclass and has a subclass specific signature in each case.<\/p>\n<p>To sum it up, the declaration &#8220;<tt> Enum&lt;E extends Enum&lt;E&gt;&gt;<\/tt> &#8221; can be deciphered as: <tt> Enum<\/tt> is a generic type that can only be instantiated for its subtypes, and those subtypes will inherit some useful methods, some of which take subtype specific arguments (or otherwise depend on the subtype).<\/p>\n<p><b>Lower Bound Type Parameters of Classes<\/b><\/p>\n<p>Type parameters can have several bounds, like in <tt> class Box&lt;T extends Number&gt; {...}<\/tt> . But a type parameter can have no lower bound, that is, a construct such as <tt> class Box&lt;T <b> great<\/b> Number&gt; {...}<\/tt> is not permitted.\u00a0 Why not?\u00a0 The answer is: it is pointless because it would not buy you anything, were it allowed.\u00a0 Let us see why lower bound type parameters of classes are confusing by exploring what an upper bound on a type parameter means.<\/p>\n<p>The upper bound on a type parameter has three effects:<\/p>\n<ol>\n<ol>\n<li><b> <i> Restricted Instantiation.<\/i> <\/b> The upper bound restricts the set of types that can be used for instantiation of the generic type.\u00a0 If we declare a <tt> class Box&lt;T extends Number&gt; {...} <\/tt> then the compiler would ensure that only subtypes of <tt> Number<\/tt> can be used as type argument.\u00a0 That is, a <tt> Box&lt;Number&gt;<\/tt> or a <tt> Box&lt;Long&gt;<\/tt> is permitted, but a <tt> Box&lt;Object&gt;<\/tt> or <tt> Box&lt;String&gt;<\/tt> would be rejected<\/li>\n<\/ol>\n<\/ol>\n<p>Example (of restricted instantiation due to an upper bound on a type parameter):<br \/>\n<tt> class Box&lt;T extends Number&gt; {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 private T value;\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public Box(T t) { value = t; }\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> }\u00a0<\/tt><tt> class Test {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public static void main(String[] args) {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Box&lt;Long&gt; boxOfLong = new Box&lt;Long&gt;(0L);\u00a0\u00a0 <b> \/\/ fine<\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Box&lt;String&gt; boxOfString = new Box&lt;String&gt;(\"\"); <b> <span style=\"color:#330000;\"> \/\/ error: String is not within bounds<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p>\n<ol>\n<li><b> <i> Access To Non-Static Members. <\/i> <\/b> The upper bound gives access to all public non-static methods and fields of the upper bound.\u00a0 In the implementation of our <tt> class Box&lt;T extends Number&gt; {...}<\/tt> we can invoke all public non-static methods defined in class <tt> Number<\/tt> , such as <tt> intValue()<\/tt> for instance.\u00a0 Without the upper bound the compiler would reject any such invocation. Example (of access to non-static members due to an upper bound on a type parameter):<\/li>\n<\/ol>\n<p><tt> class Box&lt;T extends Number&gt; {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 private T value;\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public Box(T t) { value = t; }\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public int increment() { return value.intValue()+1; } <b> \/\/ &lt;= would be an error without the Number bound<\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> }\u00a0<\/tt><\/p>\n<ol>\n<ol>\n<li><b> <i> Type Erasure. <\/i> <\/b> The leftmost upper bound is used for type erasure and replaces the type parameter in the byte code.\u00a0 In our <tt> class Box&lt;T extends Number&gt; {...}<\/tt> all occurrences of <tt> T<\/tt> would be replaced by the upper bound <tt> Number<\/tt> .\u00a0 For instance, if class <tt> Box<\/tt> has a private field of type <tt> T<\/tt> and a method <tt> void set(T content) <\/tt> for setting this private field, then the field would be of type <tt> Number<\/tt> after type erasure and the method would be translated to a method <tt> void set(Number content)<\/tt> .<\/li>\n<\/ol>\n<\/ol>\n<p>Example (of use of upper bound on a type parameter in type erasure &#8211; <i> before<\/i> type erasure):<br \/>\n<tt> class Box&lt;<b> T extends Number<\/b> &gt; {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 private <b> T<\/b> value;\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public Box(<b> T<\/b> t) { value = t; }\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> }\u00a0<\/tt><\/p>\n<ol>\n<ol>Example (of use of upper bound on a type parameter in type erasure &#8211;<\/ol>\n<\/ol>\n<p><i> after<\/i><\/p>\n<ol>\n<ol>type erasure):<\/ol>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><tt> class Box {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 private <b> Number<\/b> value;\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public Box(<b> Number<\/b> t) { value = t; }\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> }<\/tt><\/p>\n<ol>In addition, the leftmost upper bound appears in further locations, such as automatically inserted casts and bridge methods.<\/ol>\n<p>If lower bounds were permitted on type parameters, which side effects would or should they have? If a construct such as <tt> class Box&lt;T <b> great<\/b> Number&gt; {...} <\/tt> were permitted, what would it mean?\u00a0 What would the 3 side effects of an upper type parameter bound &#8211; restricted instantiation, access to non-static member, type erasure &#8211; mean for a lower bound?<\/p>\n<p><i> Restricted Instantiations. <\/i> The compiler could restrict the set of types that can be used for instantiation of the generic type with a lower bound type parameter.\u00a0 For instance, the compiler could permit instantiations such as <tt> Box&lt;Number&gt;<\/tt> and <tt> Box&lt;Object&gt;<\/tt> from a <tt> Box&lt;T <b> great<\/b> Number&gt; <\/tt> and reject instantiations such as <tt> Box&lt;Long&gt;<\/tt> or <tt> Box&lt;Short&gt;<\/tt> .\u00a0 This would be an effect in line with the restrictive side-effect described for upper type parameter bounds.<\/p>\n<p><i> Access To Non-Static Members. <\/i> A lower type parameter bound does not give access to any particular methods beyond those inherited from class <tt> Object<\/tt> . In the example of <tt> Box&lt;T <b> great<\/b> Number&gt; <\/tt> the supertypes of <tt> Number<\/tt> have nothing in common, except that they are reference types and therefore subtypes of <tt> Object<\/tt> .\u00a0 The compiler cannot assume that the field of type <tt> T<\/tt> is of type <tt> Number<\/tt> or a subtype thereof.\u00a0 Instead, the field of type <tt> T<\/tt> can be of any supertype of <tt> Number<\/tt> , such as <tt> Serializable<\/tt> or <tt> Object<\/tt> .\u00a0 The invocation of a method such as <tt> intValue()<\/tt> is no longer type-safe and the compiler would have to reject it. As a consequence, the lower type parameter bound would not give access to an non-static members beyond those defined in class <tt> Object<\/tt> and thus has the same effect as &#8220;no bound&#8221;.<\/p>\n<p><i> Type Erasure<\/i> .\u00a0 Following this line of logic, it does not make sense to replace the occurrences of the type parameter by its leftmost lower bound.\u00a0 Declaring a method like the constructor <tt> Box(<b> T<\/b> t) <\/tt> as a constructor <tt> Box(<b> Number<\/b> t)<\/tt> does not make sense, considering that <tt> T<\/tt> is replaced by a supertype of <tt> Number<\/tt> .\u00a0 An <tt> Object<\/tt> might be rightly passed to the constructor in an instantiation <tt> Box&lt;Object&gt;<\/tt> and the constructor would reject it.\u00a0 This would be dead wrong.\u00a0\u00a0 So, type erasure would replace all occurrences of the type variable<tt> T<\/tt> by type <tt> Object<\/tt> , and not by its lower bound.\u00a0 Again, the lower bound would have the same effect as &#8220;no bound&#8221;.<\/p>\n<p>Do you want to figure out what it would mean if both lower <i> _and_<\/i> upper bounds were permitted?\u00a0\u00a0 Personally, I don&#8217;t even want to think about it and would prefer to file it under &#8220;not manageable&#8221;, if you permit.<\/p>\n<p>The bottom line is: all that a &#8220;<tt> great<\/tt> &#8221; bound would buy you is the restriction that only supertypes of <tt> Number<\/tt> can be used as type arguments.\u00a0 And even that is frequently misunderstood.\u00a0 It would NOT mean that <tt> class Box&lt;T super Number&gt; {...}<\/tt> contains only instances of supertypes of <tt> Number<\/tt> .\u00a0 Quite the converse &#8211; as the example below demonstrates!<\/p>\n<p>Example (of use of upper bound on a type parameter in type erasure &#8211; <i> before<\/i> type erasure):<\/p>\n<div style=\"margin-left:40px;\">\n<blockquote><p><tt> class Box&lt;<b> T super Number<\/b> &gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0 private <b> T<\/b> value;<\/tt><br \/>\n<tt> \u00a0\u00a0 public Box(<b> T<\/b> t) { value = t; }<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<\/div>\n<p>Example (of use of upper bound on a type parameter in type erasure &#8211; <i> after<\/i> type erasure):<\/p>\n<div style=\"margin-left:40px;\">\n<blockquote><p><tt> class Box {<\/tt><br \/>\n<tt> \u00a0\u00a0 private <b> Object<\/b> value;<\/tt><br \/>\n<tt> \u00a0\u00a0 public Box(<b> Object<\/b> t) { value = t; }<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<\/div>\n<p>A <tt> class Box&lt;T <b> great<\/b> Number&gt; {...} <\/tt> would be translated by type erasure to a <tt> Box<\/tt> containing an <tt> Object<\/tt> field and it&#8217;s constructor would be translated to <tt> Box(Object t)<\/tt> . That&#8217;s fundamentally different from a <tt> class Box&lt;T <b> extends<\/b> Number&gt; {...}<\/tt> , which would be translated to a <tt> Box<\/tt> containing a <tt> Number<\/tt> field and it&#8217;s constructor would be translated to <tt> Box(Number t)<\/tt> . Consequently, a <tt> Box&lt;Number&gt;<\/tt> instantiated from a<tt> class Box&lt;T extends Number&gt; {...}<\/tt> would be different from a <tt> Box&lt;Number&gt;<\/tt> instantiation from a <tt> class Box&lt;T super Number&gt; {...}<\/tt> , which is likely to cause confusion.\u00a0 For this reason lower bounds do not make sense on type parameters of classes.<\/p>\n<p>&nbsp;<\/p>\n<hr width=\"100%\" \/>\n<p>&nbsp;<\/p>\n<p><b>Lower Bound Type Parameters of Methods<\/b><\/p>\n<p>In conjunction with methods and their argument types, a type parameter with a lower bound can occasionally be useful.<\/p>\n<p>Example (of a method that would benefit from a type parameter with a lower bound):<\/p>\n<blockquote><p><tt> class Pair&lt;X,Y&gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0 private X first;<\/tt><br \/>\n<tt> \u00a0\u00a0 private Y second;<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> \u00a0\u00a0 public &lt;<b> A super X<\/b> ,<b> B super Y<\/b> &gt; B addToMap(Map&lt;A,B&gt; map) { \/\/ error: type parameter cannot have lower bound<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return map.put(first, second);<\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><br \/>\n<tt> class Test {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public static void main(String[] args) {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Pair&lt;String,Long&gt; pair = new Pair&lt;&gt;(\"ABC\",42L);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Map&lt;CharSequence, Number&gt; map = HashMap&lt;CharSequence, Number&gt;();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Number number = pair.addToMap(map);<\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The <tt> addToMap()<\/tt> method adds the content of the pair to a map.\u00a0 Any map that can hold supertypes of <tt> X<\/tt> and <tt> Y<\/tt> would do.\u00a0 The map&#8217;s <tt> put()<\/tt> method returns the value found in the map for the given key, if there already is a key-value entry for the key in the map.\u00a0 The return value of the map&#8217;s <tt> put()<\/tt> method shall be returned from the <tt> addToMap()<\/tt> method.\u00a0 Under these circumstances one would like to declare the method as shown above: The map is parameterized with supertypes of the pair&#8217;s type parameters and the <tt> addToMap()<\/tt> method&#8217;S return type is the map&#8217;s value type.<\/p>\n<p>Since the compiler does not allow lower bounds on type parameters we need a work-around.<\/p>\n<p>One work-around that comes to mind is the use of a wildcard, because wildcards can have a lower bound.\u00a0 Here is a work-around using a wildcard.<\/p>\n<p>Example (of a work-around for the previous example using wildcards):<\/p>\n<blockquote><p><tt> class Pair&lt;X,Y&gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0 private X first;<\/tt><br \/>\n<tt> \u00a0\u00a0 private Y second;<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> \u00a0\u00a0 public <b> Object<\/b> addToMap(Map&lt;<b> ? Super X<\/b> , <b> ? super Y<\/b> &gt; map) {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return map.put(first, second);<\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><br \/>\n<tt> class Test {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public static void main(String[] args) {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Pair&lt;String,Long&gt; pair = new Pair&lt;&gt;(\"ABC\",42L);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Map&lt;CharSequence, Number&gt; map = HashMap&lt;CharSequence, Number&gt;();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Number number = <b> (Number)<\/b> pair.addToMap(map);<\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>It works, except that there is no way to declare the return type as desired.\u00a0 It would be the supertype of <tt> Y<\/tt> that the compiler captures from the map type, but there is no syntax for specifying it.\u00a0 We must not declare the return type a &#8220;<tt> ? super Y<\/tt> &#8220;, because &#8220;<tt> ? super Y<\/tt> &#8221; is a wildcard and not a type and therefore not permitted as a return type. We have no choice and must use <tt> Object<\/tt> instead as our method&#8217;s return type.\u00a0 This rather unspecific return type in turn forces callers of the <tt> addToMap()<\/tt> method into casting the return value down from <tt> Object<\/tt> to its actual type.\u00a0 This is not exactly what we had in mind.<\/p>\n<p>Another work-around is use of static methods.\u00a0 Here is a work-around with a static instead of a non-static method.<\/p>\n<p>Example (of a work-around for the previous example using a static method):<\/p>\n<blockquote><p><tt> class Pair&lt;X,Y&gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0 private X first;<\/tt><br \/>\n<tt> \u00a0\u00a0 private Y second;<\/tt><br \/>\n<tt> \u00a0\u00a0 ...<\/tt><br \/>\n<tt> \u00a0\u00a0 public <b> static<\/b> &lt;<b> A<\/b> ,<b> B<\/b> ,X <b> extends A<\/b> ,Y <b> extends B<\/b> &gt; B addToMap(Pair&lt;X,Y&gt; pair, Map&lt;<b> A<\/b> ,<b> B<\/b> &gt; map) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return map.put(pair.first,pair.second);<\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><br \/>\n<tt> class Test {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0 public static void main(String[] args) {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Pair&lt;String,Long&gt; pair = new Pair&lt;&gt;(\"ABC\",42L);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Map&lt;CharSequence, Number&gt; map = HashMap&lt;CharSequence, Number&gt;();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0 Number number = <b> Pair<\/b> .addToMap(<b> pair<\/b> ,map);<\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The generic <tt> addToMap()<\/tt> method has four type parameters: two placeholders <tt> X<\/tt> and <tt> Y<\/tt> for the pair&#8217;s type and two placeholders <tt> A<\/tt> and <tt> B <\/tt> for the map&#8217;s type. <tt> A<\/tt> and <tt> B<\/tt> are supertypes of <tt> X<\/tt> and <tt> Y<\/tt> , because <tt> X<\/tt> and <tt> Y<\/tt> \u00a0 are declared with <tt> A<\/tt> and <tt> B<\/tt> as their upper bounds. (Note, that the generic method&#8217;s type parameters <tt> X<\/tt> and <tt> Y<\/tt> have nothing to do with the <tt> Pair<\/tt> class&#8217;s <tt> X<\/tt> and <tt> Y<\/tt> parameters.\u00a0 The names <tt> X<\/tt> and <tt> Y<\/tt> are reused for the generic method to make them easily recognizable as the pair&#8217;s type parameters. Using four type parameters we can declare the precise return type as desired: it is the same type as the value type of the map.<\/p>\n<p>Example (of illegal use of type parameter in static context of a generic class):<\/p>\n<blockquote><p><tt> class SomeClass<b> <span style=\"color:#000099;\"> &lt;T&gt;<\/span> <\/b> {<\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> static initializer, static field, static method<\/i><br \/>\n<tt> \u00a0 <b> static<\/b> {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 SomeClass&lt;<b> <span style=\"color:#000099;\"> T<\/span> <\/b> &gt; test = new SomeClass&lt;<b> <span style=\"color:#000099;\"> T<\/span> <\/b> &gt;(); <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private <b> static<\/b> <b> <span style=\"color:#000099;\"> T<\/span> <\/b> globalInfo;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 public\u00a0 <b> static<\/b> <b> <span style=\"color:#000099;\"> T <\/span> <\/b> getGlobalInfo() {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 return globalInfo;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> non-static initializer, non-static field, non-static method<\/i><br \/>\n<tt> \u00a0 {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 SomeClass&lt;<b> <span style=\"color:#000099;\"> T<\/span> <\/b> &gt; test = new SomeClass&lt;<b> <span style=\"color:#000099;\"> T<\/span> <\/b> &gt;();<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#000099;\"> T<\/span> <\/b> localInfo;<\/tt><br \/>\n<tt> \u00a0 public\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getLocalInfo() {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 return localInfo;<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> static nested types<\/i><br \/>\n<tt> \u00a0 public <b> static<\/b> <b> class<\/b> Failure extends Exception {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 private final <b> <span style=\"color:#000099;\"> T<\/span> <\/b> info;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public Failure(<b> <span style=\"color:#000099;\"> T<\/span> <\/b> t) { info = t; }\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getInfo() { return info; }\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0 private <b> interface<\/b> Copyable {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 <b> <span style=\"color:#000099;\"> T<\/span> <\/b> copy();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private <b> enum<\/b> State {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 VALID, INVALID;<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 private <b> <span style=\"color:#000099;\"> T<\/span> <\/b> info; \/\/ error<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public void setInfo(<b> <span style=\"color:#000099;\"> T<\/span> <\/b> t) { info = t; } <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getInfo() { return info; }\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> non-static nested types<\/i><br \/>\n<tt> \u00a0 public <b> class<\/b> Accessor {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getInfo() { return localInfo; }<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The example illustrates that the type parameter cannot be used in the static context of a generic class.\u00a0 It also shows that nested interfaces and enum types are considered static type members of the class.\u00a0 Only inner classes, that is, non-static nested classes, can use the type parameter of the enclosing generic class.<\/p>\n<p>The scope of an interface&#8217;s type parameter is the entire definition of the interface, except any fields or nested types.\u00a0 This is because fields and nested types defined in an interface are implicitly static.<\/p>\n<p>Example (of illegal use of type parameter in a generic interface):<\/p>\n<blockquote><p><tt> interface SomeInterface<b> <span style=\"color:#000099;\"> &lt;T&gt;<\/span> <\/b> {<\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> field<\/i><br \/>\n<tt> \u00a0 SomeClass&lt;<b> <span style=\"color:#000099;\"> T<\/span> <\/b> &gt; value = new SomeClass&lt;<b> <span style=\"color:#000099;\"> T<\/span> <\/b> &gt;();\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> nested type<\/i><br \/>\n<tt> \u00a0 <b> class<\/b> Accessor {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 public <b> <span style=\"color:#000099;\"> T <\/span> <\/b> getInfo() {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <b> <span style=\"color:#660000;\"> \/\/ error<\/span> <\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return value.getGlobalInfo();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 \/\/ <\/tt> <i> methods<\/i><br \/>\n<tt> \u00a0 <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getValue();<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>The example shows that fields of an interface are implicitly static, so that the type parameter cannot be used anywhere in the declaration of a field of a generic interface.\u00a0 Similarly, the nested class is considered a static nested class, not an inner class, and for this reason use of the type parameter anywhere in the nested class is illegal.<\/p>\n<p><b> <i> Workaround for nested static classes and interfaces:<\/i> <\/b><\/p>\n<p>In case of static nested classes and interfaces this is not a major calamity.\u00a0 As a workaround we can generate the static class or interface itself.<\/p>\n<p>Example (workaround &#8211; generate the nested static type):<\/p>\n<blockquote><p><tt> class Wrapper<b> <span style=\"color:#000099;\"> &lt;T&gt;<\/span> <\/b> {<\/tt><br \/>\n<tt> \u00a0 private final <b> <span style=\"color:#000099;\"> T<\/span> <\/b> theObject;<\/tt><\/p><\/blockquote>\n<blockquote><p><tt> \u00a0 public Wrapper(<b> <span style=\"color:#000099;\"> T<\/span> <\/b> t) { theObject = t; }<\/tt><br \/>\n<tt> \u00a0 public <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getWrapper() { return theObject; }<\/tt><tt> \u00a0 public Immutable<b> &lt;T&gt;<\/b> makeImmutable() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return new Immutable<b> &lt;T&gt;<\/b> (theObject);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public Mutable<b> &lt;T&gt;<\/b> makeMutable() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return new Mutable<b> &lt;T&gt;<\/b> (theObject);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private static &lt;A&gt; A makeClone(A theObject) { ... }<\/tt><\/p>\n<p><tt> \u00a0 public static final class Immutable<b> &lt;A&gt;<\/b> { <b> \/\/ is a generic class now<\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 private final <b> A<\/b> theObject;<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public Immutable(<b> A<\/b> arg) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 theObject = makeClone(arg);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public <b> A<\/b> getWrappedItem() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return makeClone(theObject);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public static class Mutable<b> &lt;A&gt;<\/b> {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ... similar ...<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>There is no such workaround for nested enum types because they cannot be generic.<\/p>\n<p><b> <i> Workaround for nested static classes:<\/i> <\/b><\/p>\n<p>If the nested static type is a class, an alternative workaround would be turning the static class into a non-static inner class.<\/p>\n<p>Example (workaround &#8211; use an inner class):<\/p>\n<blockquote><p><tt> class Wrapper<b> <span style=\"color:#000099;\"> &lt;T&gt;<\/span> <\/b> {<\/tt><br \/>\n<tt> \u00a0 private final <b> <span style=\"color:#000099;\"> T<\/span> <\/b> theObject;<\/tt><\/p><\/blockquote>\n<blockquote><p><tt> \u00a0 public Wrapper(<b> <span style=\"color:#000099;\"> T<\/span> <\/b> t) { theObject = t; }<\/tt><br \/>\n<tt> \u00a0 public <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getWrapper() { return theObject; }<\/tt><tt> \u00a0 public Mutable makeMutable() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return <b> this.<\/b> new Mutable(theObject);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public Immutable makeImmutable() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return <b> this.<\/b> new Immutable(theObject);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private static &lt;A&gt; A makeClone(A theObject) { ... }<\/tt><\/p>\n<p><tt> \u00a0 public final class Immutable {\u00a0 <b> \/\/ is no longer a static class<\/b> <\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 private final <b> T<\/b> theObject;<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0\u00a0\u00a0 public Immutable(<b> T<\/b> arg) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 theObject = makeClone(arg);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 public <b> T<\/b> getWrappedItem() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return makeClone(theObject);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public class Mutable\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ... similar ...<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>This workaround comes with a certain amount of overhead because all inner classes have a hidden reference to an instance of the outer type, which in this example they neither need nor take advantage of; the hidden reference is just baggage.\u00a0 Often, inner classes are combined with interfaces in order to keep the inner class a private implementation detail of the enclosing class.\u00a0 We can do the same here.<\/p>\n<p>Example (the previous workaround refined):<\/p>\n<blockquote><p><tt> class Wrapper<b> <span style=\"color:#000099;\"> &lt;T&gt;<\/span> <\/b> {<\/tt><br \/>\n<tt> \u00a0 private final <b> <span style=\"color:#000099;\"> T<\/span> <\/b> theObject;<\/tt><\/p><\/blockquote>\n<blockquote><p><tt> \u00a0 public Wrapper(<b> <span style=\"color:#000099;\"> T<\/span> <\/b> t) { theObject = t; }<\/tt><br \/>\n<tt> \u00a0 public <b> <span style=\"color:#000099;\"> T<\/span> <\/b> getWrapper() { return theObject; }<\/tt><tt> \u00a0 public Mutable<b> &lt;T&gt;<\/b> makeMutable() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return this.new Mutable(theObject);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 public Immutable<b> &lt;T&gt;<\/b> makeImmutable() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 return this.new Immutable(theObject);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 private static &lt;A&gt; A makeClone(A theObject) { ... }<\/tt><\/p>\n<p><tt> \u00a0 <b> public interface <\/b> Immutable&lt;S&gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 S getWrappedItem();<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 <b> public interface <\/b> Mutable&lt;S&gt; {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 S getWrappedItem();<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 void setWrappedItem(S arg);<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 <b> private<\/b> final class ImmutableImplementation <b> implements Immutable&lt;T&gt;<\/b> {\u00a0<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0\u00a0\u00a0 private final T theObject;<\/tt><\/p>\n<p><tt> \u00a0\u00a0\u00a0\u00a0\u00a0 public ImmutableImplementation(T arg) {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 theObject = makeClone(arg);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 public T getWrappedItem() {<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return makeClone(theObject);<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0 }<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> \u00a0 <b> private<\/b> class MutableImplementation <b> implements Mutable&lt;T&gt;<\/b> {\u00a0<\/tt><br \/>\n<tt> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ... similar ...<\/tt><br \/>\n<tt> \u00a0 }<\/tt><br \/>\n<tt> }<\/tt><\/p><\/blockquote>\n<p>As you can see, the nested public interfaces need to be generic whereas the inner private classes can use the enclosing class&#8217;s type parameter.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<table width=\"100%\" cellpadding=\"10\">\n<tbody>\n<tr valign=\"TOP\">\n<td colspan=\"2\" width=\"68%\"><b>\u00a0<\/b><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please see this FAQ for more information: <a href=\"http:\/\/www.angelikalanger.com\/GenericsFAQ\/JavaGenericsFAQ.html#SECTION1\" rel=\"nofollow\">http:\/\/www.angelikalanger.com\/GenericsFAQ\/JavaGenericsFAQ.html#SECTION1<\/a> Here in short form some important points from this FAQ. Example (of a generic type): class Pair&lt;X,Y&gt; { private X first; \u00a0 private Y second; \u00a0 public Pair(X a1, Y a2) { \u00a0\u00a0\u00a0 first = a1; \u00a0\u00a0\u00a0 second = a2; \u00a0 } \u00a0 public X getFirst() [&hellip;]<\/p>\n","protected":false},"author":65283547,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Generics in short form","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1017],"tags":[18369,2549795,6280762],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-java","tag-generics","tag-java","tag-java-generics"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4CoHV-v","jetpack-related-posts":[{"id":2532,"url":"https:\/\/vkrastev1blog.com\/2026\/10\/02\/%d0%b2%d1%82%d0%be%d1%80%d0%b8%d1%8f%d1%82-%d0%b2%d1%81%d0%b5%d0%bb%d0%b5%d0%bd%d1%81%d0%ba%d0%b8-%d1%81%d1%8a%d0%b1%d0%be%d1%80-%d0%b2-%d0%ba%d0%be%d0%bd%d1%81%d1%82%d0%b0%d0%bd%d1%82%d0%b8%d0%bd\/","url_meta":{"origin":31,"position":0},"title":"The second ecumenical council in Constantinople (381) - the confirmation of the doctrine of the Holy Spirit","author":"vkrastev2014","date":"02.10.2026","format":false,"excerpt":"\u0412\u0442\u043e\u0440\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440 \u0432 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d\u043e\u043f\u043e\u043b (381 \u0433.) \u2013 \u0443\u0442\u0432\u044a\u0440\u0436\u0434\u0430\u0432\u0430\u043d\u0435\u0442\u043e \u043d\u0430 \u0443\u0447\u0435\u043d\u0438\u0435\u0442\u043e \u0437\u0430 \u0421\u0432\u0435\u0442\u0438\u044f \u0414\u0443\u0445 \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u043d\u0430 \u0445\u0440\u0438\u0441\u0442\u0438\u044f\u043d\u0441\u0442\u0432\u043e\u0442\u043e \u2022 \u0412\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440\u0438 \u2022 IV \u0432\u0435\u043a \u0412\u0442\u043e\u0440\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0435\u0437 381 \u0433. \u0432 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d\u043e\u043f\u043e\u043b, \u0435 \u0435\u0434\u043d\u043e \u043e\u0442 \u043d\u0430\u0439-\u0432\u0430\u0436\u043d\u0438\u0442\u0435 \u0441\u044a\u0431\u0438\u0442\u0438\u044f \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u0442\u0430 \u043d\u0430 \u0440\u0430\u043d\u043d\u043e\u0442\u043e \u0445\u0440\u0438\u0441\u0442\u0438\u044f\u043d\u0441\u0442\u0432\u043e. \u041d\u0430 \u043d\u0435\u0433\u043e \u0435 \u043f\u043e\u0442\u0432\u044a\u0440\u0434\u0435\u043d\u0430 \u041d\u0438\u043a\u0435\u0439\u0441\u043a\u0430\u0442\u0430 \u0432\u044f\u0440\u0430 \u043e\u0442 325\u2026","rel":"","context":"In &quot;Articles devoted to the Bible and about the spirit and the body&quot;","block_context":{"text":"Articles devoted to the Bible and about the spirit and the body","link":"https:\/\/vkrastev1blog.com\/category\/%d1%81%d1%82%d0%b0%d1%82%d0%b8%d0%b8-%d0%bf%d0%be%d1%81%d0%b2%d0%b5%d1%82%d0%b5%d0%bd%d0%b8-%d0%bd%d0%b0-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d0%b7%d0%b0-%d0%b4%d1%83%d1%85%d0%b0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/ebtppy-v5hhqxqbousaxhde8pmrm8ky9vg5zhq_i42gf-itvech_wr25ui-u_ruov2gkqenknbbx2y7ekwwxzt8559wmlq424iif_pbcon6riek_ttdbxwp75aulyh3_naxhvg_pukcmdvjs88b30esv3xgtigs1gsziujd02gs.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/ebtppy-v5hhqxqbousaxhde8pmrm8ky9vg5zhq_i42gf-itvech_wr25ui-u_ruov2gkqenknbbx2y7ekwwxzt8559wmlq424iif_pbcon6riek_ttdbxwp75aulyh3_naxhvg_pukcmdvjs88b30esv3xgtigs1gsziujd02gs.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/ebtppy-v5hhqxqbousaxhde8pmrm8ky9vg5zhq_i42gf-itvech_wr25ui-u_ruov2gkqenknbbx2y7ekwwxzt8559wmlq424iif_pbcon6riek_ttdbxwp75aulyh3_naxhvg_pukcmdvjs88b30esv3xgtigs1gsziujd02gs.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/ebtppy-v5hhqxqbousaxhde8pmrm8ky9vg5zhq_i42gf-itvech_wr25ui-u_ruov2gkqenknbbx2y7ekwwxzt8559wmlq424iif_pbcon6riek_ttdbxwp75aulyh3_naxhvg_pukcmdvjs88b30esv3xgtigs1gsziujd02gs.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/ebtppy-v5hhqxqbousaxhde8pmrm8ky9vg5zhq_i42gf-itvech_wr25ui-u_ruov2gkqenknbbx2y7ekwwxzt8559wmlq424iif_pbcon6riek_ttdbxwp75aulyh3_naxhvg_pukcmdvjs88b30esv3xgtigs1gsziujd02gs.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/ebtppy-v5hhqxqbousaxhde8pmrm8ky9vg5zhq_i42gf-itvech_wr25ui-u_ruov2gkqenknbbx2y7ekwwxzt8559wmlq424iif_pbcon6riek_ttdbxwp75aulyh3_naxhvg_pukcmdvjs88b30esv3xgtigs1gsziujd02gs.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":2549,"url":"https:\/\/vkrastev1blog.com\/2026\/10\/02\/%d0%bf%d0%b5%d1%82%d0%b8%d1%8f%d1%82-%d0%b2%d1%81%d0%b5%d0%bb%d0%b5%d0%bd%d1%81%d0%ba%d0%b8-%d1%81%d1%8a%d0%b1%d0%be%d1%80-%d0%b2-%d0%ba%d0%be%d0%bd%d1%81%d1%82%d0%b0%d0%bd%d1%82%d0%b8%d0%bd%d0%be\/","url_meta":{"origin":31,"position":1},"title":"The Fifth Ecumenical Council of Constantinople (553): The Three Heads Controversy, Chalcedon's Theological Legacy, and the Politics of Emperor Justinian I","author":"vkrastev2014","date":"02.10.2026","format":false,"excerpt":"\u041f\u0435\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440 \u0432 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d\u043e\u043f\u043e\u043b (553 \u0433.): \u0441\u043f\u043e\u0440\u044a\u0442 \u0437\u0430 \u201e\u0422\u0440\u0438\u0442\u0435 \u0433\u043b\u0430\u0432\u0438\u201c, \u0431\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u0441\u043a\u043e\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u043e \u043d\u0430 \u0425\u0430\u043b\u043a\u0438\u0434\u043e\u043d \u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u0442\u0430 \u043d\u0430 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u042e\u0441\u0442\u0438\u043d\u0438\u0430\u043d I \u0420\u0435\u0437\u044e\u043c\u0435: \u041f\u0435\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440, \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u0430\u0442\u043e \u0412\u0442\u043e\u0440\u0438\u044f \u0441\u044a\u0431\u043e\u0440 \u0432 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d\u043e\u043f\u043e\u043b, \u0441\u0435 \u043f\u0440\u043e\u0432\u0435\u0436\u0434\u0430 \u043f\u0440\u0435\u0437 553 \u0433. \u043f\u043e \u0432\u0440\u0435\u043c\u0435 \u043d\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u0442\u043e \u043d\u0430 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u042e\u0441\u0442\u0438\u043d\u0438\u0430\u043d I. \u041d\u0435\u0433\u043e\u0432\u0430\u0442\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430 \u0446\u0435\u043b \u0435 \u0434\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u2026","rel":"","context":"In &quot;Articles devoted to the Bible and about the spirit and the body&quot;","block_context":{"text":"Articles devoted to the Bible and about the spirit and the body","link":"https:\/\/vkrastev1blog.com\/category\/%d1%81%d1%82%d0%b0%d1%82%d0%b8%d0%b8-%d0%bf%d0%be%d1%81%d0%b2%d0%b5%d1%82%d0%b5%d0%bd%d0%b8-%d0%bd%d0%b0-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d0%b7%d0%b0-%d0%b4%d1%83%d1%85%d0%b0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_51_20-pm.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_51_20-pm.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_51_20-pm.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_51_20-pm.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_51_20-pm.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_51_20-pm.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":657,"url":"https:\/\/vkrastev1blog.com\/2024\/10\/19\/%d0%bc%d0%be%d1%8f-%d0%bf%d0%be%d0%b3%d0%bb%d0%b5%d0%b4-%d0%b7%d0%b0-%d0%b1%d0%be%d0%b3-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d1%85%d1%80%d0%b8%d1%81%d1%82%d0%be%d1%81\/","url_meta":{"origin":31,"position":2},"title":"My view of God, the Bible and Christ","author":"vkrastev2014","date":"19.10.2024","format":false,"excerpt":"\u0418\u043a\u043e\u043d\u0430 \u043d\u0430 \u0418\u0441\u0443\u0441 \u0425\u0440\u0438\u0441\u0442\u043e\u0441 \u0417\u0434\u0440\u0430\u0432\u0435\u0439\u0442\u0435 \u0438\u0441\u043a\u0430\u043c \u0434\u0430 \u0441\u043f\u043e\u0434\u0435\u043b\u044f \u043c\u043e\u0438\u0442\u0435 \u0440\u0430\u0437\u0441\u044a\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u043a \u0437\u0430 \u0411\u043e\u0433 \u0438 \u0437\u0430 \u0425\u0440\u0438\u0441\u0442\u043e\u0441. \u0410\u0437 \u0441\u044a\u043c \u043d\u043e\u0432 \u0432\u044a\u0432 \u0432\u044f\u0440\u0430\u0442\u0430 \u0438 \u0442\u0435\u043f\u044a\u0440\u0432\u0430 \u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438 \u0434\u0430 \u0443\u0447\u0430 \u043f\u043e\u0432\u0435\u0447\u0435 \u0437\u0430 \u0411\u043e\u0433. \u041e\u043f\u0438\u0442\u0432\u0430\u043c \u0441\u0438 \u0434\u0430 \u0441\u0438 \u043e\u0431\u044f\u0441\u043d\u044f \u043d\u0435\u0449\u0430\u0442\u0430 \u043a\u0430\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u043a \u0438 \u0438\u043d\u0436\u0438\u043d\u0435\u0440 \u043d\u043e \u0441\u0438 \u043c\u0438\u0441\u043b\u044f, \u0447\u0435 \u0447\u043e\u0432\u0435\u0448\u043a\u0438\u044f \u043c\u043e\u0437\u044a\u043a \u043d\u0435 \u043c\u043e\u0436\u0435 \u0434\u0430\u2026","rel":"","context":"In &quot;Articles devoted to the Bible and about the spirit and the body&quot;","block_context":{"text":"Articles devoted to the Bible and about the spirit and the body","link":"https:\/\/vkrastev1blog.com\/category\/%d1%81%d1%82%d0%b0%d1%82%d0%b8%d0%b8-%d0%bf%d0%be%d1%81%d0%b2%d0%b5%d1%82%d0%b5%d0%bd%d0%b8-%d0%bd%d0%b0-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d0%b7%d0%b0-%d0%b4%d1%83%d1%85%d0%b0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2024\/10\/image-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1733,"url":"https:\/\/vkrastev1blog.com\/2025\/01\/29\/%d0%b7%d0%b0-%d0%b1%d0%be%d0%b3-%d0%b8-%d0%b2%d1%81%d0%b5%d0%bb%d0%b5%d0%bd%d0%b0%d1%82%d0%b0\/","url_meta":{"origin":31,"position":3},"title":"For God and the Universe","author":"vkrastev2014","date":"29.01.2025","format":false,"excerpt":"\u041f\u0440\u0438\u0447\u0438\u043d\u0438 \u0434\u0430 \u0432\u044f\u0440\u0432\u0430\u043c\u0435, \u0447\u0435 \u0411\u043e\u0433 \u043d\u0430\u0438\u0441\u0442\u0438\u043d\u0430 \u0441\u044a\u0449\u0435\u0441\u0442\u0432\u0443\u0432\u0430. \u043e\u0442 \u041c\u0435\u0440\u0438\u043b\u0438\u043d \u0410\u0434\u0430\u043c\u0441\u044a\u043d \u0412\u0441\u0435\u043b\u0435\u043d\u0430\u0442\u0430 \u0438\u043c\u0430 \u043d\u0430\u0447\u0430\u043b\u043e - \u043a\u0430\u043a\u0432\u043e \u0433\u043e \u0435 \u043f\u0440\u0435\u0434\u0438\u0437\u0432\u0438\u043a\u0430\u043b\u043e? \u0423\u0447\u0435\u043d\u0438\u0442\u0435 \u0441\u0430 \u0443\u0431\u0435\u0434\u0435\u043d\u0438, \u0447\u0435 \u043d\u0430\u0448\u0430\u0442\u0430 \u0412\u0441\u0435\u043b\u0435\u043d\u0430 \u0435 \u0437\u0430\u043f\u043e\u0447\u043d\u0430\u043b\u0430 \u0441 \u0435\u0434\u043d\u0430 \u043e\u0433\u0440\u043e\u043c\u043d\u0430 \u0435\u043a\u0441\u043f\u043b\u043e\u0437\u0438\u044f \u043d\u0430 \u0435\u043d\u0435\u0440\u0433\u0438\u044f \u0438 \u0441\u0432\u0435\u0442\u043b\u0438\u043d\u0430, \u043a\u043e\u044f\u0442\u043e \u043d\u0430\u0440\u0438\u0447\u0430\u043c\u0435 \u0413\u043e\u043b\u0435\u043c\u0438\u044f\u0442 \u0432\u0437\u0440\u0438\u0432. \u0422\u043e\u0432\u0430 \u0435\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0441\u044a\u0431\u0438\u0442\u0438\u0435 \u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u043e \u043d\u0430\u0447\u0430\u043b\u043e\u0442\u043e \u043d\u0430 \u0432\u0441\u0438\u0447\u043a\u043e, \u043a\u043e\u0435\u0442\u043e \u0441\u044a\u0449\u0435\u0441\u0442\u0432\u0443\u0432\u0430: \u0412\u0441\u0435\u043b\u0435\u043d\u0430\u0442\u0430, \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u0442\u043e\u2026","rel":"","context":"In &quot;Articles devoted to the Bible and about the spirit and the body&quot;","block_context":{"text":"Articles devoted to the Bible and about the spirit and the body","link":"https:\/\/vkrastev1blog.com\/category\/%d1%81%d1%82%d0%b0%d1%82%d0%b8%d0%b8-%d0%bf%d0%be%d1%81%d0%b2%d0%b5%d1%82%d0%b5%d0%bd%d0%b8-%d0%bd%d0%b0-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d0%b7%d0%b0-%d0%b4%d1%83%d1%85%d0%b0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2025\/01\/093e0eeeb6f9dbc2d2ef6a13bec53c59-20240927143705-1.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2025\/01\/093e0eeeb6f9dbc2d2ef6a13bec53c59-20240927143705-1.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2025\/01\/093e0eeeb6f9dbc2d2ef6a13bec53c59-20240927143705-1.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2025\/01\/093e0eeeb6f9dbc2d2ef6a13bec53c59-20240927143705-1.jpeg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2537,"url":"https:\/\/vkrastev1blog.com\/2026\/10\/02\/%d1%82%d1%80%d0%b5%d1%82%d0%b8%d1%8f%d1%82-%d0%b2%d1%81%d0%b5%d0%bb%d0%b5%d0%bd%d1%81%d0%ba%d0%b8-%d1%81%d1%8a%d0%b1%d0%be%d1%80-%d0%b2-%d0%b5%d1%84%d0%b5%d1%81-431-%d0%b3-%d1%85%d1%80%d0%b8%d1%81\/","url_meta":{"origin":31,"position":4},"title":"The Third Ecumenical Council of Ephesus (431): the Christological dispute between Cyril of Alexandria and Nestorius and the affirmation of the doctrine of the Mother of God","author":"vkrastev2014","date":"02.10.2026","format":false,"excerpt":"\u0422\u0440\u0435\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440 \u0432 \u0415\u0444\u0435\u0441 (431 \u0433.): \u0445\u0440\u0438\u0441\u0442\u043e\u043b\u043e\u0433\u0438\u0447\u043d\u0438\u044f\u0442 \u0441\u043f\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u041a\u0438\u0440\u0438\u043b \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440\u0438\u0439\u0441\u043a\u0438 \u0438 \u041d\u0435\u0441\u0442\u043e\u0440\u0438\u0439 \u0438 \u0443\u0442\u0432\u044a\u0440\u0436\u0434\u0430\u0432\u0430\u043d\u0435\u0442\u043e \u043d\u0430 \u0443\u0447\u0435\u043d\u0438\u0435\u0442\u043e \u0437\u0430 \u0411\u043e\u0433\u043e\u0440\u043e\u0434\u0438\u0446\u0430 \u041d\u0430\u0443\u0447\u043d\u043e-\u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u043e \u0438 \u0431\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u0441\u043a\u043e \u0438\u0437\u0441\u043b\u0435\u0434\u0432\u0430\u043d\u0435 \u0410\u0432\u0442\u043e\u0440: \u0412\u0435\u043b\u0438\u0441\u043b\u0430\u0432 \u041a\u0440\u044a\u0441\u0442\u0435\u0432\u0422\u0435\u043c\u0430: \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u043d\u0430 \u0440\u0430\u043d\u043d\u0430\u0442\u0430 \u0426\u044a\u0440\u043a\u0432\u0430 \u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u043d\u0430 \u0445\u0440\u0438\u0441\u0442\u043e\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u0442\u0430 \u0434\u043e\u0433\u043c\u0430\u0442\u0438\u043a\u0430\u041f\u0435\u0440\u0438\u043e\u0434: 428\u2013451 \u0433.\u041e\u0441\u043d\u043e\u0432\u043d\u043e \u0441\u044a\u0431\u0438\u0442\u0438\u0435: \u0422\u0440\u0435\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440, \u0415\u0444\u0435\u0441, 431 \u0433. \u0420\u0435\u0437\u044e\u043c\u0435 \u0422\u0440\u0435\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u2026","rel":"","context":"In &quot;Articles devoted to the Bible and about the spirit and the body&quot;","block_context":{"text":"Articles devoted to the Bible and about the spirit and the body","link":"https:\/\/vkrastev1blog.com\/category\/%d1%81%d1%82%d0%b0%d1%82%d0%b8%d0%b8-%d0%bf%d0%be%d1%81%d0%b2%d0%b5%d1%82%d0%b5%d0%bd%d0%b8-%d0%bd%d0%b0-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d0%b7%d0%b0-%d0%b4%d1%83%d1%85%d0%b0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_12_12-pm.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_12_12-pm.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_12_12-pm.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_12_12-pm.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_12_12-pm.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/chatgpt-image-oct-2-2026-08_12_12-pm.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":2556,"url":"https:\/\/vkrastev1blog.com\/2026\/10\/02\/%d1%88%d0%b5%d1%81%d1%82%d0%b8%d1%8f%d1%82-%d0%b2%d1%81%d0%b5%d0%bb%d0%b5%d0%bd%d1%81%d0%ba%d0%b8-%d1%81%d1%8a%d0%b1%d0%be%d1%80-%d0%b2-%d0%ba%d0%be%d0%bd%d1%81%d1%82%d0%b0%d0%bd%d1%82%d0%b8%d0%bd\/","url_meta":{"origin":31,"position":5},"title":"The Sixth Ecumenical Council of Constantinople (680\u2013681): the condemnation of monothelitism and the affirmation of the two wills and the two actions in Jesus Christ","author":"vkrastev2014","date":"02.10.2026","format":false,"excerpt":"\u0428\u0435\u0441\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440 \u0432 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d\u043e\u043f\u043e\u043b (680\u2013681 \u0433.): \u043e\u0441\u044a\u0436\u0434\u0430\u043d\u0435\u0442\u043e \u043d\u0430 \u043c\u043e\u043d\u043e\u0442\u0435\u043b\u0438\u0442\u0441\u0442\u0432\u043e\u0442\u043e \u0438 \u0443\u0442\u0432\u044a\u0440\u0436\u0434\u0430\u0432\u0430\u043d\u0435\u0442\u043e \u043d\u0430 \u0434\u0432\u0435\u0442\u0435 \u0432\u043e\u043b\u0438 \u0438 \u0434\u0432\u0435\u0442\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0418\u0438\u0441\u0443\u0441 \u0425\u0440\u0438\u0441\u0442\u043e\u0441 \u041d\u0430\u0443\u0447\u043d\u043e-\u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0430 \u0441\u0442\u0430\u0442\u0438\u044f \u0437\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0432\u0430\u043d\u0435 \u0432 WordPress \u0420\u0435\u0437\u044e\u043c\u0435: \u0428\u0435\u0441\u0442\u0438\u044f\u0442 \u0432\u0441\u0435\u043b\u0435\u043d\u0441\u043a\u0438 \u0441\u044a\u0431\u043e\u0440, \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u0430\u0442\u043e \u0422\u0440\u0435\u0442\u0438\u044f \u0441\u044a\u0431\u043e\u0440 \u0432 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d\u043e\u043f\u043e\u043b, \u0441\u0435 \u043f\u0440\u043e\u0432\u0435\u0436\u0434\u0430 \u0432 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 680\u2013681 \u0433. \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u0442\u043e \u043d\u0430 \u0432\u0438\u0437\u0430\u043d\u0442\u0438\u0439\u0441\u043a\u0438\u044f \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0438\u043d IV\u2026","rel":"","context":"In &quot;Articles devoted to the Bible and about the spirit and the body&quot;","block_context":{"text":"Articles devoted to the Bible and about the spirit and the body","link":"https:\/\/vkrastev1blog.com\/category\/%d1%81%d1%82%d0%b0%d1%82%d0%b8%d0%b8-%d0%bf%d0%be%d1%81%d0%b2%d0%b5%d1%82%d0%b5%d0%bd%d0%b8-%d0%bd%d0%b0-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d1%8f%d1%82%d0%b0-%d0%b8-%d0%b7%d0%b0-%d0%b4%d1%83%d1%85%d0%b0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/yxsv0k-cfybsgrn4iacbsni6wvorwsimqx4mcnk6i7vvno8-yygtibr2p6c7uhf18h7kykuh-oqxfnmevvk2efigpws1vzqug_m-ryim8mdynspdwkucquhts-ckr3g53iyvlogvjhinycbsjewtpqbgjh-apj7ffnumanhcavu.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/yxsv0k-cfybsgrn4iacbsni6wvorwsimqx4mcnk6i7vvno8-yygtibr2p6c7uhf18h7kykuh-oqxfnmevvk2efigpws1vzqug_m-ryim8mdynspdwkucquhts-ckr3g53iyvlogvjhinycbsjewtpqbgjh-apj7ffnumanhcavu.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/yxsv0k-cfybsgrn4iacbsni6wvorwsimqx4mcnk6i7vvno8-yygtibr2p6c7uhf18h7kykuh-oqxfnmevvk2efigpws1vzqug_m-ryim8mdynspdwkucquhts-ckr3g53iyvlogvjhinycbsjewtpqbgjh-apj7ffnumanhcavu.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/yxsv0k-cfybsgrn4iacbsni6wvorwsimqx4mcnk6i7vvno8-yygtibr2p6c7uhf18h7kykuh-oqxfnmevvk2efigpws1vzqug_m-ryim8mdynspdwkucquhts-ckr3g53iyvlogvjhinycbsjewtpqbgjh-apj7ffnumanhcavu.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/vkrastev1blog.com\/wp-content\/uploads\/2026\/10\/yxsv0k-cfybsgrn4iacbsni6wvorwsimqx4mcnk6i7vvno8-yygtibr2p6c7uhf18h7kykuh-oqxfnmevvk2efigpws1vzqug_m-ryim8mdynspdwkucquhts-ckr3g53iyvlogvjhinycbsjewtpqbgjh-apj7ffnumanhcavu.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]}],"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/users\/65283547"}],"replies":[{"embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":8,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/posts\/31\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vkrastev1blog.com\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}