Java interface throws an exception but interface implementation does not throw an exception? -


i read code interface throws exception, class implements doesn't throw 1 or catch one, why that? legal or safe in java?

import java.rmi.*; public interface myremote extends remote {     public string sayhello() throws remoteexception; }  import java.rmi.*; import java.rmi.server.*; public class myremoteimpl extends unicastremoteobject implements myremote{     public string sayhello() {         return "server says, 'hey'";     }     public myremoteimpl() throws remoteexception {}     public static void main (string[] args) {         try {              myremote service = new myremoteimpl();              naming.rebind("remotehello", service);         } catch(exception ex)         {             ex.printstacktrace();         }     } } 

a general rule of implementing , extending can make new class or interface "less restrictive" not "more restrictive". if think of requirement handle exception restriction, implementation doesn't declare exception less restrictive. codes interface not have trouble class.

— stan james


as part of discussion @ http://www.coderanch.com/t/399874/java/java/methods-throwing-exception-interface


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -