Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:27:23+00:00 2026-05-14T03:27:23+00:00

The following compiles fine: Object o = new Object(); System.out.println(o instanceof Cloneable); But this

  • 0

The following compiles fine:

  Object o = new Object();
  System.out.println(o instanceof Cloneable);

But this doesn’t:

  String s = new String();
  System.out.println(s instanceof Cloneable);

A compiler error is thrown.

What is the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:27:23+00:00Added an answer on May 14, 2026 at 3:27 am

    A more blatant incarnation of your problem is the following:

    if ("foo" instanceof Number)
       // "Incompatible conditional operand types String and Number"
    

    This is specified in JLS 15.20.2 Type comparison operator instanceof:

    RelationalExpression:
           RelationalExpression instanceof ReferenceType
    

    If a cast of the RelationalExpression to the ReferenceType would be rejected as a compile-time error, then the instanceof relational expression likewise produces a compile-time error. In such a situation, the result of the instanceof expression could never be true.

    That is, since this cast expression generates a compile time error:

    (Number) "foo"
    

    so must this expression:

    ("foo" instanceof Number)
    

    Your case is a bit more subtle, but the principle is the same:

    • String is a final class
    • String does not implement Cloneable
    • Therefore you can’t do (Cloneable) aString
    • Therefore also you can’t do aString instanceof Cloneable
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In script#, I have the following: jQuery.Select(#someId).Trigger(item-added, new object[]{ball} ); This compiles into the
This confuses me. The following compiles fine under Eclipse. package com.example.gotchas; public class GenericHelper1
In Microsoft Oslo SDK CTP 2008 (using Intellipad) the following code compiles fine: module
I came across the following code that compiles fine (using Visual Studio 2005): SomeObject
The following code compiles correctly under VC++ 8 on XPSP3, but running it causes
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
We just recently upgraded from VS2008 to VS2010. Our project compiles fine; but when
i am trying to XML serialize a class object but having the following problem:
This code reads and updates the form fine when I run the program, but
I have the following code: Dim compiler As ICodeCompiler = New Microsoft.JScript.JScriptCodeProvider().CreateCompiler Dim params

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.