Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichael McDonald
2,877 PointsCan we always reuse type names and variable names?
Most languages won't allow the declaration of URL as a string when URL is already a data type.
1 Answer
Harry James
14,780 PointsHey again Michael! :)
In Java, you need to specifically declare what the variable's data type is. Some languages will already decide that a URL is in fact a URL (I know, that sounds silly but it's true) whereas Java has no idea what it is unless you tell specifically tell it.
So, in Java, we are free to do what we want, we can declare a URL like a string (As long as we use quotes). Note that the two sides must always be balanced though. So, we can do:
Uri myUri = Uri.parse("http://www.google.com/");
but we can't do
Uri myUri = "http://www.google.com/";
// Unbalanced!
because Java is expecting a Uri but instead gets a String (I'm using Uri's here instead of URL's because they are more convenient to use in Android thanks to the parse method.).
Hope this clarifies things and, if you have any more questions, give me a shout! :)
Michael McDonald
2,877 PointsMichael McDonald
2,877 PointsThank you Harry. I think I understand.