Pregunta

I'm creating a UML static class diagram for AsyncTask. How should I denote doInBackground(Params... params), which has a variable number of argumetns?

¿Fue útil?

Solución

OK, so, first, apologies to @JBNizet for blatant code stealing (original URL to the stolen code: here).

The thing is that Java 5's varargs is just syntactic sugar for an array. Witness this code:

class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        foo(args);
    }

    private static void foo(String... params) {
        System.out.println(Arrays.toString(params));
    }
}

It works. It would have worked the same if instead you had used a varargs in main() and an array in foo().

So, in UML, you can model varargs as an array.

Otros consejos

AFAIK UML does not allow to do so. But if you look from the other side: varargs in Java is just an Array of objects. I believe from modeling perspective this should not make any differene.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top