diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java b/src/main/java/org/apache/commons/csv/CSVRecord.java index e42d34a1..072be8b3 100644 --- a/src/main/java/org/apache/commons/csv/CSVRecord.java +++ b/src/main/java/org/apache/commons/csv/CSVRecord.java @@ -176,7 +176,7 @@ public final class CSVRecord implements Serializable, Iterable { * @param map The Map to populate. * @return the given map. */ - Map putIn(final Map map) { + > M putIn(final M map) { for (final Entry entry : mapping.entrySet()) { map.put(entry.getKey(), values[entry.getValue().intValue()]); } diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index 8a9ff4f6..895c8467 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import org.junit.Assert; @@ -133,6 +134,9 @@ public class CSVRecordTest { final Map map = new ConcurrentHashMap(); this.recordWithHeader.putIn(map); this.validateMap(map, false); + // Test that we can compile with assigment to the same map as the param. + final TreeMap map2 = recordWithHeader.putIn(new TreeMap()); + this.validateMap(map2, false); } @Test @@ -141,7 +145,7 @@ public class CSVRecordTest { final CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT); final Map map = recordWithHeader.toMap(); map.remove("OldColumn"); - map.put("NewColumn", "NewValue"); + map.put("ZColumn", "NewValue"); // check: final ArrayList list = new ArrayList(map.values()); Collections.sort(list);