Reputation: 11
following is the scenario that I am encountering
I have this set of string here
Set<String> attributes = new LinkedHashSet<>();
yet I have another function with a signature LinkedHashSet
public static List<String> rerankAttributesByType (LinkedHashSet<String> attributeList)
is it safe for me to just cast attributes to LinkedHashSet and proceed with the function calls?
List<String> newAttributes = rerankAttributesByType((LinkedHashSet<String>) unselectedAttribute)
Upvotes: 0
Views: 698
Reputation: 198391
This is technically safe, since you know the actual concrete type, but not good practice.
Instead, change
public static List<String> rerankAttributesByType(LinkedHashSet<String> attributeList)
to
public static List<String> rerankAttributesByType (Set<String> attributeList)
so you don't have to do a cast, and you can properly use the interface type throughout your program.
Upvotes: 0