Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is package level restriction?

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday I was just to add a file in package which comes with java. Like java.lang
I wrote following code



and got following error when tried to run that class.




I want to know that how they achieved package level restriction? I know that some may feel this question absolute baseless because naming a package which is already there makes no sense. But i just want to know that what really happens and how they have done it? If someone can help me that will be very helpful to me.

Thanks a lot for reading this.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace makes it pretty clear that it's implemented by java.security.SecureClassLoader .
 
Peter Lawrey
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Sun license agreement, which you agreed to when you downloaded Java states you cannot modify or add to standard packages such as java.* and javax.*, sun.* and com.sun.*

Solution: Use your own package.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter.

Have you gone through the whole agreement before accepting it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic