Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Instantiating an interface
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
np_123




PostPosted: Mon Jan 18, 2016 11:02 pm   Post subject: Instantiating an interface

So I know some stuff about coding in Java, and the basics of how encapsulation and other OOP concepts work, but this code excerpt(not my own) kinda surprised me...
You can't instantiate abstract classes and you can't instantiate regular interfaces so what's so special about a nested/inner interface that allows this code to run? Also, when and why would you instantiate an interface?

Java:

public class Shuffler {

        public interface IShuffle{
                public void shuffle(int[]a);
        }

        public static void main(String[] args) {
                int m=Integer.parseInt("10");
                int n=Integer.parseInt("100000");
                IShuffle shuffle=new IShuffle(){
                        public void shuffle(int[]a){
                                for(int i=0;i<a.length;i++){
                                        int r=i+new Random().nextInt(a.length-i);
                                        int temp=a[i];
                                        a[i]=a[r];
                                        a[r]=temp;
                                }
                        }

        }

}
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Tue Jan 19, 2016 6:30 pm   Post subject: RE:Instantiating an interface

looks like this has been answered here.
np_123




PostPosted: Tue Jan 19, 2016 6:49 pm   Post subject: RE:Instantiating an interface

hmm, yeah that's interesting. haven't really come across that type of usage before
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: