I am currently working on a project using Objectdb and Im using NetBeans.
I want to have a myString method that can appear this message :
Variable type is int.
when im calling the object Driver from another main class
[
import javax.persistence.*;
import java.util.*;
//import javax.jdo.*;
import java.sql.*;
public class Main {
public static void Element(Object obj){
System.out.println(obj);
}//end method Element
public static void main(String[] args) {
Element(Driver);
}//end main
]
Of course I don’t want to type exactly this thing so I can print it,
but instead I want a method that can return int if its an integer, String if it is String etc.
When it come to a String variable it is ok.
But when I have an integer it shows me the message “int cannot be dereferenced” so the compiler won’t pass this.
Is this a way to work it around correctly?
This is importart so thanks in advance.
import javax.persistence.*;
import java.util.*;
@Entity
public class Driver{
@Id
private int Driverid;
public void setDriverid(int Driverid) {
this.Driverid= Driverid;
}
public int getDriverid() {
return Driverid;
}
public Driver(int getDriverid){
this.Driverid=Driverid;
}
public String toString() {
return "Variable type is " + Driverid.getClass.getSimpleName() + "." ;
}//end toString
}//end class Driver
Try with using the
Integerclass instead ofint. int is a primitive type, Integer is not.