Title: Confused about this generics use case
Tags: java;generics
Question: What i understand from this code is that genericDao is supposed to return  an object of type TypeLiteral<T&gt; where T extends Bean.class .
public <T extends Bean&gt; TypeLiteral<T&gt; genericDao() {
return (TypeLiteral<T&gt;) TypeLiteral.get(Types.newParameterizedType(
GenericDao.class, type, getKey()));
But shouldn't the method have been written  this way ?
public  TypeLiteral< T extends Bean&gt; genericDao() {
return (TypeLiteral<T&gt;) TypeLiteral.get(Types.newParameterizedType(
GenericDao.class, type, getKey()));

Here is the accepted answer: That's the syntax for generic methods.
The <T extends Bean&gt; in the method declaration tells us that the method uses generics, and you can use T inside the method body as a type.
In your code, T has no meaning.

Here is another answer: For a generic method the parameterized type specification is separate from the return type. See the examples here. For instance:
static <T&gt; void fromArrayToCollection(T[] a, Collection<T&gt; c) {
for (T o : a) {
c.add(o); // Correct
So this example returns void but is parameterized with <T&gt;. In your case you paramterize with <T extends Bean&gt; and return TypeLiteral<T&gt;. In your second example the compiler would not know the type of T, as the method is not declared as a generic method but as a regular one.

Here is another answer: Without going into complex details of Java Language Spec, simple reason for the syntax is because the type parameter T could be used several times within the method declaration, eg:
public <T extends Bean&gt; TypeLiteral<T&gt; genericDao(T param1, T param2) {
T localvar1;
T localvar2;
Having to specify T extends Bean everytime is redundant and unecessary

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:09/12/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><generics>', 'Title': 'Confused about this generics use case', 'ViewCount': 100, 'id': 18757122, 'user_AboutMe': None, 'user_AccountId': 2890995.0, 'user_DisplayName': 'osh', 'user_Reputation': 1111.0, 'user_Views': 48.0, 'user_id': 2479792.0}}