• Post Reply Bookmark Topic Watch Topic
  • New Topic

array declarations  RSS feed

 
ilteris kaplan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, so in my code I have three PFont object which I am trying to wrap into an array and pass into another object through a constructor and here is what I got.



what I am wondering is there a nicer way to declare those fonts[] elements other than hardcoding like above. I have tried a for loop but it didn't work out since I coulnd't find a way to reference font1, font2, font3 in a generic way.

What would you guys use instead of this? Thanks alot.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can (and should) dispense with the variables altogether. You can do something like:



The array size is determined automatically, so it's really easy to add new elements.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need the variables font1, font2, font3 at all. You can assign the return value of the loadFont() method calls to the array elements directly.
 
ilteris kaplan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh that's so sweet indeed!!

Thanks alot guys.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!