Results 1 to 4 of 4
  1. #1
    kprime is offline Member
    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0

    Default Cloneable/cannot find symbol question

    Hi,

    I have a question about an error message I'm getting. Here is my code:

    Java Code:
    class Base implements Cloneable
    {
    	public void clone(Base base) throws CloneNotSupportedException	
    	{
    		new Base().clone();	
    		clone();
    	}
    }
    
    public class TestProtected 
    {
    	public static void main(String[] args)
    	{	
    		new Base().clone(); // compilation error: symbol not found
    	}
    }
    My question is just that why am I getting a symbol not found rather than clone has protected access in Object error?

    When I remove the clone method in Base, then I get the expected protected access error.

    Thank you.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Cloneable/cannot find symbol question

    Your clone method takes a Base parameter.
    The proper clone() method takes no parameters.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    kprime is offline Member
    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0

    Default Re: Cloneable/cannot find symbol question

    I understand but the clone(Base) is overloading the clone method correct? So my Base class should have two clone methods one that takes Base and the one inherited from Object. Why can't I attempt to call the clone method inherited from Object which takes no parameters?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Cloneable/cannot find symbol question

    From the API for Cloneable:

    By convention, classes that implement this interface should override Object.clone (which is protected) with a public method

Similar Threads

  1. cannot find symbol
    By vastrolorde in forum New To Java
    Replies: 11
    Last Post: 01-04-2013, 11:11 AM
  2. Cannot find symbol errors question
    By zlloyd1 in forum New To Java
    Replies: 1
    Last Post: 12-17-2012, 03:24 PM
  3. cannot find symbol
    By GabWit in forum New To Java
    Replies: 3
    Last Post: 01-25-2009, 12:13 AM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •