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 trialJennifer Bird
4,287 PointsCan't get past Casting Object as String...
so.. I should create a method public getTitlefromObject() { return (something) } ...?
3 Answers
Jennifer Bird
4,287 PointsI tried this and it didn't work actually...
public static String getTitleFromObject(Object obj){
String result = " ";
if (obj instanceof String) {
return (String) obj;
} else {
return ((BlogPost) obj).getTitle();
}
}
Steve Hunter
57,712 PointsHi Jennifer,
Have a look through this post to see if that helps you out.
Let me know how you get on.
Steve.
Steve Hunter
57,712 PointsI just pasted your code in and it worked fine - what error are you getting and does clicking Preview give you any clues?
Have you added your code in the TypeCastChecker.java
file?
Steve.
Steve Hunter
57,712 PointsAnd have you set both HINT values back to false
?