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 trial

Java Java Data Structures - Retired Getting There Type Casting

Jennifer Bird
Jennifer Bird
4,287 Points

Can't get past Casting Object as String...

so.. I should create a method public getTitlefromObject() { return (something) } ...?

3 Answers

Jennifer Bird
Jennifer Bird
4,287 Points

I 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(); 
    }
  }

Hi Jennifer,

Have a look through this post to see if that helps you out.

Let me know how you get on.

Steve.

I 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.

And have you set both HINT values back to false?