2

enter image description here

I am doing some DB operation, using Loader, populating a HashMap and then filling a TreeMap with this HashMap for Sorting puropse, however when I try to pass this TreeMap to my AsyncTask like:

Sorted = new TreeMap<Date,String>(BD); 
new MagicCall().execute(Sorted); 

But the compiler is giving me a warning: Type safety: A generic array of Map is created for a varargs parameter

This is my AsyncTask Declaration:

private class MagicCall extends AsyncTask<Map<Date,String>, String, String>

Any Heading?

User3
  • 2,465
  • 8
  • 41
  • 84
  • Java does not like generics in varargs http://stackoverflow.com/questions/4257883/warning-for-generic-varargs - if you don't like that warning wrap that `TreeMap` into a class without generics. – zapl Nov 29 '13 at 12:53
  • Will it cost me anything if I suppress it? – User3 Nov 29 '13 at 12:54
  • Besides 1 line of code and the possibility to violate typesafety (you should be able to pass any type of `Map` in there) no. – zapl Nov 29 '13 at 12:56
  • Thanks, then I need not bang my head against the wall. I will suppress it! – User3 Nov 29 '13 at 12:59

1 Answers1

3

I solved this problem with a workaround. You can declare your task as follows:

private class MagicCall extends AsyncTask<Void, String, String> {

  // member
  private Map<Date,String> arg = null;

  // constructor
  public MagicCall(final Map<Date,String> arg) {
    this.arg  = arg;
  }  

  ...

  @Override
  protected String doInBackground(final Void... args) {
     // do stuff on this.arg instead of args
     ...
  }
...
}

And you can call it like this:

new MagicCall(Sorted).execute();

This way you pass the task parameters through the constructor and not via the execute() method.

PJ_Finnegan
  • 1,981
  • 1
  • 20
  • 17