title: URL as field in Java Object
body: <p>I have an object which contains a field of type <code>String</code>, with a value similar to "<a href="http://stackoverflow.com">http://stackoverflow.com</a>"</p>
  
  <p>I have a method which must take a <code>URL</code>. So I am wrapping that in a method which takes the <code>String</code>, and then constructs a <code>URL</code> from the <code>String</code> (which apparently needs to be wrapped in a try catch...)</p>
  
  <p>It seems like there should be a simpler way. Is it possible to just store my value in the object as a <code>URL</code>, rather than a <code>String</code>? I tried this <code>public URL url = "http://stackoverflow.com";</code> </p>
  
  <p>Is it possible to do something along those lines? Is there a better way than what I was doing originally?</p>
  
  <p>Thanks</p>
  
  <p>original:</p>
  
  <pre><code>public String urlString = "http://stackoverflow.com";
  
  
  public boolean myMethod(String urlString) {
   try {
          URL newURL = new URL(urlString);
          useUrl(newURL);
   } catch (MalformedURLException e) {
                  e.printStackTrace();
              }
  
  }
  </code></pre>
  
  <p>Doesnt work, but seems better:</p>
  
  <pre><code>public URL url = "http://stackoverflow.com";
  
  
  public boolean myMethod(URL url) {
          useUrl(url);
    }
  </code></pre>