Jump to content

  • Log In with Google      Sign In   
  • Create Account

TheChubu

Member Since 13 Sep 2012
Offline Last Active Today, 06:44 PM

Posts I've Made

In Topic: Testing If 2 Objects Are The Same

Yesterday, 08:38 PM

You need to override "equals(Object)" of your class, and make the comparisons you need there. Probably whatever IDE you're using has a "generate equals/hashCode" refactor option to do it for you.

 

Object equality is loosely defined, so you need to provide a concrete implementation of how you expect it to be done. If you dont override "equals", you'd be calling the default equals implementation, which just compares by reference.

 

EDIT: An implementation could be something like this:

public class Test {
  String a;
  int b;
 
  public Test(String a, int b){
    this.a = a;
    this.b = b;
  }
 
  @Override
  public boolean equals(Object o) {
    // Tiny optimization.
    if (this == o) return true;
    // Null check and type check.
    if (o == null || !(o instanceof Test)) return false;
    // We know its of type Test, cast it back.
    Test tmp = (Test) o;
    // Compare int first since its faster. Then use string equality here to compare a.
    return this.b == tmp.b && Objects.equals(this.a, tmp.a); 
  }
}

Notice the Objects.equals(this.a, tmp.a). If you do this.a.equals(tmp.b), or vice versa, you risk a NPE if 'a' or 'b' is null. Objects.equals has this in mind so it checks inside first for null, then call the equals safely.


In Topic: Oracle loses Java API case against Google

27 May 2016 - 03:39 PM

 don't have any respect for the Java Foundation Class' APIs  

 

Dang it Microsoft, look at what have you done. People calling standard library "foundation classes", calling autocomplete "intellisense", next thing you know they're going to start calling git/hg/svn their "team foundation software".

 

API copyright its stupid, no matter how much of a half functional Java the Android SDK is.


In Topic: how to chose open_gl libary?

27 May 2016 - 03:27 PM

Throw a coin.

 

EDIT: Omg I downvoted GlassKnife by mistake, sorry!  :unsure:


In Topic: Should I use LWJGL 2 OR LWJGL 3?

27 May 2016 - 02:48 PM

LWJGL 3. All the nice stuff is getting developed there (GLFW for window/input management, new bindings like nanovg, stb, jemalloc, vulkan, etc).

 

LWJGL 2 has an awful windowing/input api.

 

That being said, 90% the time you'll be dealing with OpenGL, not the paticulars of LWJGL, and you better get used to find OpenGL resources in other languages (mostly C++) and then translating those concepts to Java.


In Topic: Can I write a browser game only using Java?

26 May 2016 - 07:48 PM

Are you saying that this is an okay way to go about this, converting a Java game into different languages using GWT, or should I just suck it up and learn JS + HTML?

 

If you're doing web stuff, you're not going to stay away from JS and HTML, regardless of what you use. GTW is one way that allows you to leverage what you already know. You tell me if you want to do that, or learn something new from scratch, or pick something else.

 

Honestly I havent made web games, although I do web applications (JS, HTML, C#, Microsoft stack). I'm more of a desktop guy in game dev, and I use Java for that.


PARTNERS