Вопрос

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

Это было полезно?

Решение

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top