Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Raw use of parameterized class 'ArrayList'

I have am android project I took over that that mixes Kotlin and Java, and I'm going through and converting all the Kotlin to Java, since our teams knows Java. The problem I'm running into is "Raw use of parameterized class 'ArrayList'. I can't figure out what class I'm supposed to pass to ArrayList<?> to get rid of the warning.

Here is my code:

ArrayList amenities = new ArrayList<>();

amenities.add(MapsKt.hashMapOf(
   TuplesKt.to("ID", q.amenityID),
   TuplesKt.to("bExists", q.getAnswer().equals("1")),
   TuplesKt.to("Notes", Utils.CleanStringForUpload(q.amenityNotes))
));
like image 430
jpeggtulsa Avatar asked Apr 02 '26 20:04

jpeggtulsa


1 Answers

Sounds like List<Map<String, Object>> - the list contains maps (you're adding the result of invoking hashMapOf.

That map, then, seems to map Strings, such as ID, to a grab bag of weird stuff. This is a code smell and something that needs a refactor sooner rather than later - why don't you have something like:

class WhateverThisMightBe {
    String id;
    boolean exists;
    String notesHtml;
}

and then have a List<WhateverThisMightBe> instead? That is idiomatic java/kotlin. a List<Map<String, Object>> is trying to reinvent javascript/PHP in a very cruddy fashion in java. Not a good idea.

like image 187
rzwitserloot Avatar answered Apr 04 '26 10:04

rzwitserloot