<p>Is there any shorthand way of defining and using generic definitions without having to keep repeating a particular generic description such that if there is a change I don't have to change all definitions/usages though out the codebase for example is something like this possible:</p>

<pre><code>Typedef myGenDef = &lt; Object1, Object2 &gt;;

HashMap&lt; myGenDef &gt; hm = new HashMap&lt; myGenDef &gt;();

for (Entry&lt; myGenDef &gt; ent : hm..entrySet())
{
.
.
.
}
</code></pre>

[{'answer_id': 38098, 'author': 'Aaron Maenpaa', 'author_id': 2603, 'author_profile': 'https://Stackoverflow.com/users/2603', 'pm_score': 1, 'selected': False, 'text': '<p>No. Though, groovy, a JVM language, is dynamically typed and would let you write:</p>\n\n<pre><code>def map = new HashMap&lt;complicated generic expression&gt;();\n</code></pre>\n'}, {'answer_id': 38102, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 5, 'selected': True, 'text': '<p>There\'s the <a href="http://www.ibm.com/developerworks/java/library/j-jtp02216/index.html" rel="nofollow noreferrer">pseudo-typedef antipattern</a>... </p>\n\n<pre><code>class StringList extends ArrayList&lt;String&gt; { }\n</code></pre>\n\n<p>Good stuff, drink up! ;-)</p>\n\n<p>As the article notes, this technique has some serious issues, primarily that this "typedef" is actually a separate class and thus cannot be used interchangeably with either the type it extends or other similarly defined types.</p>\n'}, {'answer_id': 38116, 'author': 'Sébastien RoccaSerra', 'author_id': 2797, 'author_profile': 'https://Stackoverflow.com/users/2797', 'pm_score': 2, 'selected': False, 'text': '<p>In a generic method, you can use a limited form of type inferrence to avoid some repetitions.</p>\n\n<p>Example: if you have the function</p>\n\n<pre><code>    &lt;K, V&gt; Map&lt;K, V&gt; getSomething() {\n        //...\n    }\n</code></pre>\n\n<p>you can use:</p>\n\n<pre><code>final Map&lt;String, Object&gt; something = getsomething();\n</code></pre>\n\n<p>instead of:</p>\n\n<pre><code>final Map&lt;String, Object&gt; something = this.&lt;String, Object&gt;getsomething();\n</code></pre>\n'}, {'answer_id': 38118, 'author': 'zaca', 'author_id': 3031, 'author_profile': 'https://Stackoverflow.com/users/3031', 'pm_score': 2, 'selected': False, 'text': '<p>Use <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern" rel="nofollow noreferrer">Factory Pattern</a> for creation of Generics:</p>\n\n<p>Method Sample:</p>\n\n<pre><code>public Map&lt;String, Integer&gt; createGenMap(){\n        return new HashMap&lt;String,Integer&gt;();\n\n    }\n</code></pre>\n'}, {'answer_id': 39325, 'author': 'Marcio Aguiar', 'author_id': 4213, 'author_profile': 'https://Stackoverflow.com/users/4213', 'pm_score': 2, 'selected': False, 'text': '<p>The pseudo-typedef antipattern mentioned by Shog9 would work - though it\'s not recommended to use an ANTIPATTERN - but it does not address your intentions. The goal of pseudo-typedef is to reduce clutter in declaration and improve readability. </p>\n\n<p>What you want is to be able to replace a group of generics declarations by one single trade. I think you have to stop and think: "in witch ways is it valuable?". I mean, I can\'t think of a scenario where you would need this. Imagine class A:</p>\n\n<pre><code>class A {\n     private Map&lt;String, Integer&gt; values = new HashMap&lt;String, Integer&gt;();\n}\n</code></pre>\n\n<p>Imagine now that I want to change the \'values\' field to a Map. Why would exist many other fields scattered through the code that needs the same change? As for the operations that uses \'values\' a simple refactoring would be enough.</p>\n'}]
['https://Stackoverflow.com/questions/38068', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']