-
object check
I am writing a program for a local texting app. one of the things i need to do is check if files exist. and if they don't, then to take action. here is the code that checks what the method returns (either "true" or "false" Code:
checkParams check = new checkParams();
System.out.println(check);
if (check.equals("true")) {
System.out.println("There are some files that do not exist!");
}
when i print out check, i get "true", but this does not print out...
-
Re: object check
Have you overriden checkParams equals() method?
-
Re: object check
gr.... i thought since it would return a string, i could use that directly. but i guess it just sets the object = to that string.
checkParams check = new checkParams();
System.out.println(check.toString());
if(check.toString().equals("true")) {
System.out.println("hi");
}
-
Re: object check
:confused:
If all the checkParams class does is hold a "true" or "false" String then why not just use boolean or Boolean?
-
Re: object check
not sure what you are saying. are you saing the checkParams class should return a boolean instead?
-
Re: object check
No. You appear to be comparing a checkParams object to the String "true". I was just confused as to what purpose the checkParams class is because if you want to know if it is "true" then the first thing that comes to my mind is boolean. Without context it seems that your checkParams class is a pseudo boolean object. If so then why not just use a boolean and get rid of the checkParams class?
-
Re: object check
ok, so i guess i need to kinda re-think this. what if the checkParams checked if the files exist, and if there are any errors, it would return them in an array of strings?
-
Re: object check
Check if what files exist? The Java API has a File class which has a method that performs a check. Perhaps you should be using that instead. But then again since I have no idea what your overall goal is, it could be the wrong thing to do.