Is it possible to make a method that takes any number of arguments?

I looked at another post that described what seems like my problem : How to make a method that accepts any number of arguments of any type in Java?

However , when I tried to make this method, when I compiled the program that it gave me, the error "int could not be converted to java.util.Objects"

What am I doing wrong?

code:

public static void clearArray (Objects... args)
{
    System.out.println("Error, non character value");
}

As I called the function:

import java.util.Objects;
// Stuff...
clearArray(1);
// Other stuff...

Thanks for watching my problem!

+4
source share
2 answers

You want java.lang.Object, not java.util.Objects.

java.util.Objects - , , .

java.lang.Object , Java.

(varargs) Object ..., Objects ....

+6

public static void clearArray (Objects... args)

receivng Object type . ,

public static void clearArray (Object... args)

.

+7

Source: https://habr.com/ru/post/1611853/


All Articles