Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm relatively new to Java, and to Forge, and this has been bugging me for a bit. Often times I'll realize I have to call a getter function (e.g. Minecraft.getInstance) every time an event is fired. So to get around this I'll sometimes create a field in the class and set it once. Or in the case of a loop I'll store the value in a local variable and refer back to the variable. I'm used to doing this in languages like C, where optimization and garbage collection isn't exactly the same concept as it is in Java.

 

So my question is, how much of this is necessary? Does it really matter if I call the getter functions a bunch? Does it add any overhead? Memory leaks? Anything? Why are there so many? Sorry if this is more of a Java question. I'm really only using Java for Forge and so the answer will have a significant impact on how I write mods.

 

Thanks ?

  • Author
14 minutes ago, V0idWa1k3r said:

Pretty much all getters are internally optimized by the JVM.

So does this mean there's no performance difference between object.field and object.getField()?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.