I was looking at another post here which was describing what seems to be my problem: How to make a method which accepts any number of arguments of any type in Java?
However, when I attempted to do this method, when I compiled the program it gave me the error "int cannot be converted to java.util.Objects"
What am I doing wrong?
public static void clearArray (Objects... args)
{
System.out.println("Error, non character value");
}
import java.util.Objects;
// Stuff...
clearArray(1);
// Other stuff...
Thank you for checking out my problem!
Look at the signature
public static void clearArray (Objects... args)
That method receivng Objects type and you are passing integer to it. Perhaps changing that to
public static void clearArray (Object... args)
Helps.
You want java.lang.Object
, not java.util.Objects
.
java.util.Objects
is a class with utility methods, not a class you can actually extend and instantiate.
java.lang.Object
on the other hand is the superclass of all objects in Java.
And even in a multi-param (varargs) method, the signature needs to be Object ...
, not Objects ...
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With