Error converting Java to String: Cannot convert nonconforming type; Java.lang.String to String

Asked 1 years ago, Updated 1 years ago, 337 views

I was doing an exercise to string numbers in Java reference books, but when I tried to compile the code as an example, an error was displayed for the following parts:
If you are familiar with Java, please let me know.

Where applicable:

s=Integer.toString(i,2);
s = integer.toString(i,16);

error messages:

Incompatible type; unable to convert java.lang.String to String

source code:

class String {
    public static void main(String args[]){
        Strings;      
        inti = 45;

        s = Integer.toString(i,2);
        System.out.println(s);
    
        s = Integer.toString(i,16);
        System.out.println(s);
    }
}

java

2022-09-30 22:00

2 Answers

class String {
      public static void main(String args[]){
          Strings;      

This s is an instance of the String class created by the questioner.Instead of Java standard String.

Rename your String or s declaration to java.lang.String;.


2022-09-30 22:00

The code in the question text creates a class named String, but it is different than expected because it is named String with Java built-in


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.