Java static instance -


so started fist big project in java , i'm following tutorial there code dont understand @ all.

package com.legolando.runa;  import net.minecraftforge.fml.common.mod;  @mod(modid = reference.modid, name = reference.modname, version = reference.version) public class runa {  @mod.instance public static runa instance = new runa(); //  dont why instance of class has static   } 

as see create instance of class inside class (already cosmos me) , instance static. can explain static instance? same static variable or method?

this code reminds me of singleton class in java.

public class runa {     private static runa singleton = new runa( );     /* private constructor prevents other     * class instantiating.     */    private runa() { }     /* static 'instance' method */    public static runa getinstance( ) {       return singleton;    }     /* other methods protected singleton-ness */    protected static void demomethod( ) {       system.out.println("demomethod singleton");    } } 

fyi, singleton ensures 1 object of created class runa inside application. try google bit more understanding of singleton usage in java

links: https://www.tutorialspoint.com/java/java_using_singleton.htm

best of luck


Comments

  1. Well explained . Great article on OOP . There is also good java resource for beginners visit Java Tutorials   

    ReplyDelete

Post a Comment

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -