As the (non-functioning) code below shows, I want to take any hashmap and convert to spreadsheet format.
def printHashMapToCsv[T](m:Map[T,T],name:String, path:String): Unit =
{
Spreadsheet.initCsvSpreadsheet(name,path)
m.foreach
{
e=> Spreadsheet.addCell(IDGenerator.getInstance().nextID(),e._1.toString,e._2.toString)
}
Spreadsheet.printCsvFinal()
}
The code above compiles, but I get a compilation method when I try to call the method using the code below:
def mapOut(): Unit =
{
try{
val m:mutable.HashMap[Int,String]=new mutable.HashMap[Int,String]()
m.put(1,"sssss")
m.put(2,"ghfd")
m.put(3,"dfsa")
m.put(4,"fhjgsdf")
printHashMapToCsv(m,"mapout",s"${new File(".").getAbsolutePath}${File.separator}unitTestOutput")
}
Compilation error:
error: type mismatch; [INFO] found : scala.collection.mutable.HashMap[Int,String] [INFO] required: Map[?,?]
Any advice would be appreciated
printHashMapToCsv[T]
method expects aMap[T, T]
(i.e. both key & value of the same type) whereas you're feeding it amutable.HashMap[Int, String]
. – Leo C