Type safety: Unchecked cast from Object to ArrayList

后端 未结 5 754
情深已故
情深已故 2020-12-09 08:36

Here is a part of a program that sends an ArrayList from a server to a client. I want to remove the warning about the last line in this code:

Client code:

         


        
5条回答
  •  难免孤独
    2020-12-09 08:47

    It's impossible to avoid this warning. readObject() returns an Object. You need to cast it. And casting to a generic type will always generate such a warning.

    If you want to make your code as clean as possible, which is a good idea, you should respect the Java naming conventions though, and make variable names start with a lowercase letter.

提交回复
热议问题