Generic Method Definition contains <T extends Class> in-spite of return type is already Defined?

Vikrant Kashyap

Can any body explain why <T extends Job> Typed-safe generics is used here ??

This code was written by one of my project team member who is no more part of the team. This looks like a strange Code for me. I just want to rewrite this and use it in another Code. Without deep Understanding i won't be able to change this.

    private <T extends Job> void addNewTask (Class<T> prm_objClassToSchedule, String prm_sJobName, String prm_sTriggerName, String prm_sCronExpression) throws ParseException, SchedulerException {
            CronTrigger v_objTrigger;
            JobDetail v_objJob;
            Scheduler v_objScheduler;
}
adranale

As told in other answers T should extend Job, so the method could be clearly written like this:

private <T extends Job> void addNewTask (Class<T extends Job> prm_objClassToSchedule, String prm_sJobName, String prm_sTriggerName, String prm_sCronExpression) throws ParseException, SchedulerException {
            CronTrigger v_objTrigger;
            JobDetail v_objJob;
            Scheduler v_objScheduler;

The java compiler needs at least one mention to the exact type of the same generic type T to be able to compile it, no matter if this mention is in the parameter or in the return type. All the other mentions of T will be interpreted as the same class.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

The type already contains a definition for ' '

From Dev

The type ' ' already contains a definition for ' '

From Dev

return this from a generic method generalized with <T extends TestClass>

From Dev

Is a generic type defined in inner class / interface bound to the outer class generic type definition?

From Dev

Infer class generic property method return type

From Dev

error overriding method of class that extends generic class

From Dev

SpecFlow - The type already contains a definition for 'testRunner'

From Dev

The type 'MyApp' already contains a definition for 'MystatusBar'

From Dev

NHibernate queryover generic type that extends a class

From Dev

Java Generic class extends parametrized type

From Dev

Java generic type that either extends or is a parent class

From Dev

Check if a class is defined as generic type

From Dev

Method in generic class does not return type specified. Why?

From Dev

Single method to return an instance of different generic type of a class

From Dev

How to return class type of a generic class with generic?

From Dev

Generic method java 6 <T> before return type

From Dev

´class´ does not contains a definition for ´method´ but it´s there

From Dev

Why are the angle brackets before the return type omitted sometimes from the definition of a generic method

From Dev

java generic method return type

From Dev

Method onCreate(Bundle) is already defined in class MainActivity

From Dev

Unexpected compiler warning for "<T extends ...>" return type

From Dev

Variable length type parameters in generic class definition

From Dev

Definition of generic class: Problems with bounds on type

From Dev

Generic Class Enum Return type

From Dev

How to return the Class of a generic type

From Java

How to get the type of T from a member of a generic class or method?

From Dev

How to trigger a Generic Class method recursively changing the type of T?

From Dev

Generic return type from a generic method

From Java

Why does the compiler not enforce the return type value for a generic that extends an interface?

Related Related

  1. 1

    The type already contains a definition for ' '

  2. 2

    The type ' ' already contains a definition for ' '

  3. 3

    return this from a generic method generalized with <T extends TestClass>

  4. 4

    Is a generic type defined in inner class / interface bound to the outer class generic type definition?

  5. 5

    Infer class generic property method return type

  6. 6

    error overriding method of class that extends generic class

  7. 7

    SpecFlow - The type already contains a definition for 'testRunner'

  8. 8

    The type 'MyApp' already contains a definition for 'MystatusBar'

  9. 9

    NHibernate queryover generic type that extends a class

  10. 10

    Java Generic class extends parametrized type

  11. 11

    Java generic type that either extends or is a parent class

  12. 12

    Check if a class is defined as generic type

  13. 13

    Method in generic class does not return type specified. Why?

  14. 14

    Single method to return an instance of different generic type of a class

  15. 15

    How to return class type of a generic class with generic?

  16. 16

    Generic method java 6 <T> before return type

  17. 17

    ´class´ does not contains a definition for ´method´ but it´s there

  18. 18

    Why are the angle brackets before the return type omitted sometimes from the definition of a generic method

  19. 19

    java generic method return type

  20. 20

    Method onCreate(Bundle) is already defined in class MainActivity

  21. 21

    Unexpected compiler warning for "<T extends ...>" return type

  22. 22

    Variable length type parameters in generic class definition

  23. 23

    Definition of generic class: Problems with bounds on type

  24. 24

    Generic Class Enum Return type

  25. 25

    How to return the Class of a generic type

  26. 26

    How to get the type of T from a member of a generic class or method?

  27. 27

    How to trigger a Generic Class method recursively changing the type of T?

  28. 28

    Generic return type from a generic method

  29. 29

    Why does the compiler not enforce the return type value for a generic that extends an interface?

HotTag

Archive