Solved Java Question

Discussion in 'Spigot Plugin Development' started by Jake1996, Jun 21, 2016.

  1. Hey i got a question im not 100% sure about, ive tried googling but i guess my keywords arent great.

    Heres a scenario and hopefully you can see where im going with this:

    Code (Text):
    public void dummyMethod(){
    ArrayList<Integer> dummyArray = new ArrayList<Integer>();

    Lets say i spammed the crud out of the method, Does all those dummyArrays get stored anywhere or are they destroyed once the methods complete?

    If it seems like a silly question, im sorry. Its just one of those things i thought about and cant get over until i can figure it out lol..

    Im waiting for my book on Java to arrive, but in the meantime hopefully someone can help out

  2. As that's in a method, calling the method will add 1 and 2 to that list which keeps only one thing in memory: that list. After the method has been executed, the garbage collector will remove it from memory as you aren't using it anymore.
    • Winner Winner x 1
  3. Thought so, Thanks for clearing that up!
  4. MiniDigger


    this is a basic concept of java, it will be explained on the first few pages of your book ^^
    java has a concept called scope. if you define a variable in a method you can only access the variable in that method. once a variable is out of scope (it can't be accessed anymore) it will marked as "delteme" and the garbage collector will delete it sometimes in the (hopefully pretty near) future.
    • Like Like x 1
  5. Side note: use the superclass on the left and the type on the right:
    Code (Java):
    List<Integer> array = new ArrayList<>();
    List<Integer> array2 = new LinkedList<>();
    • Friendly Friendly x 1
  6. Also the Integer was redundant in OP's post^^
  7. For java 7+ but there are some who still use java 6.
  8. MiniDigger


    well, at least in the mc community that should not be the case anymore because even mojang moved to 1.7
    the only ppl who still use 1.6 work for big companies that can't move to newer versions quickly (like I do...)
  9. ..and sometimes you are happy if they'd at least use Java 6^^

    However those who still use an old Java version for playing Minecraft should be punished! In most cases it's pure laziness:mad: I am actually compiling my current plugin for 1.8
  10. MiniDigger


    there is no need to compile it with 1.7 anymore. since mojang is deploying a java8 se with minecraft that should be considered that standard runtime for minecraft clients and servers.
    but spigot still compiles with java 6 so....
  11. I know that Mojang does that, however Spigot servers can still run with Java 6 as you've said. And there are quite a lot that run on <1.8
    My thought was to force those who don't see it as a standard to update (also because I think that lambdas are awesome and I need a few default implementations for interface methods). If the developers don't push it, who else will?^^
  12. MiniDigger


    well, no one is using 1.6 anymore. so thats good. but the amount of 1.7 user is still quite high
    I also like the 14 pioneers we are trying out the 1.9 dev builds ^^
    • Funny Funny x 1
    • Informative Informative x 1