Announcement Announcement Module
Collapse
No announcement yet.
casting result of JpaTemplate.find() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • casting result of JpaTemplate.find()

    This is a really dumb question, and I apologize in advance.

    The JpaTemplate find() methods returns either an Object or a List<Object>. That means that we normally have to cast the return to the proper type... for example:

    Code:
    List<MyClass> results = (List<MyClass>)jpa.find(...)
    That throws a warning because it is an unchecked cast. I usually handle it with @SupressWarnings("unchecked"), but that bugs me.

    Is there a correct/clean way of doing the cast so that the warning does not happen?

    Thanks,

    b.

  • #2
    Originally posted by bmelloni View Post
    This is a really dumb question, and I apologize in advance.

    The JpaTemplate find() methods returns either an Object or a List<Object>. That means that we normally have to cast the return to the proper type... for example:

    Code:
    List<MyClass> results = (List<MyClass>)jpa.find(...)
    That throws a warning because it is an unchecked cast. I usually handle it with @SupressWarnings("unchecked"), but that bugs me.

    Is there a correct/clean way of doing the cast so that the warning does not happen?

    Thanks,

    b.
    Nope. That's what you have to do. Until these methods are 1.5 compatible and use generics you'll have to add the annotation to eliminate the warning.

    Comment


    • #3
      Ouch! We are already using 1.6 and 1.7 is on its way. And spring still stuck on 1.4... bummer.

      But thanks for your answer... at least I know "it's not me"

      Anyone hear if Spring is working to become generics-compliant?

      Comment


      • #4
        It wasn't that long ago that I was working in codebases that still used JDK 1.3 and 1.4.

        Converting a large application/api to be generics compatible is not a small chore.

        Comment

        Working...
        X