Java – what does the syntax “final string… Args” mean / do?

This should be a fairly simple question I looked around and couldn't find any topic about this grammar, and "..." made it difficult to search on Google I am developing a simple test application to copy database files from the protected location on the non root user's mobile phone to the SD card. I can access to view the location of SQLite3 database viewing tool I know it seems like a circuitous way to do things, but the simulator refuses to open on my netbook, so I now test and develop with my mobile phone

The code has been written, so I'm borrowing it from here and adjust it into my code I have encountered this short piece of code:

private class ExportDatabaseFileTask extends AsyncTask<String,Void,Boolean> {
  private final ProgressDialog dialog = new ProgressDialog(ManageData.this);

  // can use UI thread here
  protected void onPreExecute() {
     this.dialog.setMessage("Exporting database...");
     this.dialog.show();
  }

  // automatically done on worker thread (separate from UI thread)
  protected Boolean doInBackground(final String... args) {

I've never seen the parameter string... Args before What does that mean / do?

thank you! Moscro

Solution

In Java, the ellipsis of a parameter indicates vararg of type Therefore, in your case,... Means that you can pass any number of string parameters to the doinbackground method

Therefore, you can call this method doinbackground ("string1", "string2", "string3") or doinbackground ("string1") or doinbackground ("string1", "string3", "string4") or any other form

See here http://download.oracle.com/javase/1.5.0/docs/guide/language/varargs.html

Finally, it has its usual meaning By the way, this feature is available in Java 5 or later

See: http://www.developer.com/java/other/article.php/3323661

As mentioned in the above two links, it is just an array containing sugar Basically, when you define mymethod (t... Vararg), Java will treat it as mymethod (t [] vararg) When you call myobj When mymethod (T1, T2, T3,..., TN), Java passes it to myobj myMethod(new T [] {t1,tn}).

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>