title: Java: how to convert from type A to type B?
body: <p>I'm a java beginner and although I've looked for the topic both here and on Google I haven't found it. I'm sure it has to be there somewhere but it's me who doesn't know how to search. Anyway, here it is:</p>
  
  <p>How can I write methods to convert from string/int/etc. to a class and vice-versa? I'd definitely like that my class conversion be automatic but I can live with less-than-perfect typecast. What I wouldn't be comfortable with is calling class("some string") or class.toString() for converting back and forth from string to class. I'd like it to be as seamless as possible. Here's an example:</p>
  
  <p>I have a <em>IsFound</em> class that behaves like a boolean and I use it as a return type in a method; in the method body I return a string like "found" (instead of <em>true</em>). You may laugh at me for not using a Boolean but I want to play a little with a custom class/type. Here's some code</p>
  
  <pre><code>public class IsFound{
  
      public boolean found; // field
  
      public IsFound(String isFound_){
           if(isFound_.equals("FOUND")){
                found = true;
           else found = false;
           }
      }
  
      public String toString(){
      if(found)   return "found";
      else    return "not found";
      }    
  }
  </code></pre>
  
  <p>This is the furthest I could get. I need the converter methods to/from string and for future references I'd like to know whether the converters are applicable for int, char or even other classes.</p>
  
  <p>The solution to extend Boolean is only as a last resort, since I don't know what bloat I'm carrying along -- I want to create the class myself from 0.
  EDIT:
  I want to be able to use something like:</p>
  
  <pre><code>public IsFound parse(String substring_){
      if(search(substring_, string) == true){
          return FOUND; // or return "FOUND";
      {
      return NOTFOUND; // or return "NOT FOUND";
  {
  </code></pre>
  
  <p>Currently it gives the error that can't convert from String to IsFound. I want to fill in this gap.</p>