Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
SnipeBob
Dec 8, 2006

"You mechs may have copper wiring to reroute your fear of pain, but I've got nerves of steel."
I'd like to experiment with SWT. Is there anyway I can code with it using NetBeans 5.5, or do I have to use Eclipse?

Adbot
ADBOT LOVES YOU

zootm
Aug 8, 2006

We used to be better friends.
You can code with it fine in Netbeans, just reference the JAR and the libraries that it requires. The Netbeans visual designer is based on Swing and it's very unlikely you'll find an SWT designer for Netbeans, though.

Save the whales
Aug 31, 2004

by T. Finn
I have a question about traversing a class hierarchy. Let's say I have these classes:

code:
abstract class ExtendableThing
{
  String getDescription();

  String getAggregateDescription()
  {
    //???
  }
}

class ColoredThing extends ExtendableThing
{
  String getDescription()
  {
    return "colored";
  }
}

class BlueThing extends ColoredThing
{
  String getDescription()
  {
    return "blue";
  }
}

class ShinyBlueThing extends BlueThing
{
  String getDescription()
  {
    return "shiny";
  }
}
What do I put in the "getAggregateDescription" method of ExtendableThing to make it behave like this?

code:
ShinyBlueThing foo = new ShinyBlueThing();

//prints out "shiny, blue, colored"
System.out.println(foo.getAggregateDescription());

//prints out "blue, colored"
System.out.println(((BlueThing)foo).getAggregateDescription());

//prints out "colored"
System.out.println(((ColoredThing)foo).getAggregateDescription());

//prints out ""
System.out.println(((ExtendableThing)foo).getAggregateDescription());

Twitchy
May 27, 2005

Save the whales posted:

What do I put in the "getAggregateDescription" method of ExtendableThing to make it behave like this?

You might want to read up on downcasting objects, because at the moment the System.out.println statements will throw a ClassCastException. Maybe someone else who has a way with words will try and explain why (if not, read up on polymorphism).

But as far as your problem goes you could do something like:

code:
String getAggregateDescription() {
    return super.getAggregateDescription() + ", " + "blue";
}
for each of the subclasses.

Twitchy fucked around with this message at 22:41 on Apr 24, 2008

Save the whales
Aug 31, 2004

by T. Finn

Twitchy posted:

You might want to read up on downcasting objects, because at the moment System.Out.Println statements will throw a ClassCastException. Maybe someone else who has a way with words will try and explain why (if not, read up on polymorphism).

I don't see why a ClassCastException would get thrown. foo is a BlueThing, a ColoredThing, and an ExtendableThing so I don't see a problem there.

edit: I'm starting to think this isn't possible because getDescription is overwritten by each subclass. drat it.

Save the whales fucked around with this message at 22:43 on Apr 24, 2008

Twitchy
May 27, 2005

Save the whales posted:

I don't see why a ClassCastException would get thrown. foo is a BlueThing, a ColoredThing, and an ExtendableThing so I don't see a problem there.

Oops yeah you're right there, thought it was the abstract class. My apologies, always jumping the gun and looking the fool :argh:.

There's nothing else you need to put in the ExtendableThing getAggregateDescription(), since it will always call the most specific method.

So for example in ColoredThing you could have:

code:
String getAggregateDescription() {
    return super.getAggregateDescription() + ", " + "colored"
}
in BlueThing have:

code:
String getAggregateDescription() {
    return super.getAggregateDescription() + ", " + "blue"
}
in ShineyBlueThing have:

code:
String getAggregateDescription() {
    return super.getAggregateDescription() + ", " + "shiney"
}

Twitchy fucked around with this message at 22:55 on Apr 24, 2008

Save the whales
Aug 31, 2004

by T. Finn
I was hoping that I could avoid having to put the method in each subclass. This code is supposed to go in a shared library at my company and I want to make it really easy to use. So, when my coworkers are making a new kind of ExtendableThing in their projects, all they have to do is make sure it extends ExtendableThing and it works magically. If it were only one method ("getAggregateDescription") then I might have been able to deal with that, but the problem is that there are many methods that need to use a similar strategy (going up the class hierarchy).

This is what I have so far, but it's not working like I expected (it appears to cause infinite recursion):

code:
public String getAggregateDescription()
{
  if (getClass() == ExtendableThing.class)
  {
    return "";
  }
    
  StringBuilder sb = new StringBuilder();
  sb.append(getDescription());
    
  try
  {
    String superAggregateDescription = getClass().getSuperclass()
        .getMethod("getAggregateDescription").invoke(
            this, new Object[] {}).toString();

    if (superAggregateDescription != null && superAggregateDescription.length() > 0)
    {
      sb.append(", ");
      sb.append(superAggregateDescription);
    }
  }
  catch (IllegalAccessException e)
  {
    //do nothing
  }
  catch (InvocationTargetException e)
  {
    //do nothing
  }
  catch (NoSuchMethodException e)
  {
    //do nothing
  }
  catch (NullPointerException e)
  {
    //do nothing
  }
    
  return sb.toString();
}

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I discovered something awesome about java today! Labeled loops

I had a triple nested loop and the two inner loops were traversing the same data structure. I wanted to be able to break out of two loops and using a flag for this kind of stuff annoys me. I did a quick search and found the labeled loops. After reading some more I realized that you can label any block of code and effectively have a goto! It seems like it could be misused, but I'm happy with what I used it for.

code:
label: for(.....)
           for(....)
               break label;

Twitchy
May 27, 2005

Save the whales posted:

This is what I have so far, but it's not working like I expected (it appears to cause infinite recursion):

I'm not sure if this is the root of the problem but even when you upcast a ShineyBlueThing to say a BlueThing, it will still call the ShineyBlueThing getDescription() method, rather than the upcasted version (i.e. it will always print "shiny"). I think you mentioned this above, so i'm gonna have a look over it, but I don't see any "easy" way of it being done :(.

The reason it doesn't work (at least part of it) is that you're saying getClass() << ShinyBlueThing .getSuperClass() << BlueThing .getMethod("getAggregateDescription") << which doesn't exist in the BlueThing class. Even then I don't think it's quite right, you're attempting to call the same method recursivly, while at the same time not actually changing anything that would make the method path any different.

The problem may just lie in the fact that you are upcasting instead of using a new object, as in:

code:
ExtendableThing foo = new BlueThing();
System.out.println(foo.getAggregateDescription());

foo = new ShineyBlueThing();
System.out.println(foo.getAggregateDescription());
I'm not sure if this is some requirement that it has to be able to do, but if you are just going to be instantiating objects of it's subclassed types it should be ok?

Also stupid little thing but I don't think:

code:
  if (getClass() == ExtendableThing.class)
  {
    return "";
  }
should be needed since you can't instantiate ExtendableThing in the first place.

Edit: Jesus christ, sorry this post is all over the place :|

Twitchy fucked around with this message at 23:47 on Apr 24, 2008

Save the whales
Aug 31, 2004

by T. Finn
I think I've got it! At least, this solution appears to work. I avoid the problem of the method being overwritten by declaring new instances of the super classes and abandoning recursion.

code:
public String getAggregateDescription()
{
  StringBuilder sb = new StringBuilder();
  Class c = getClass();
  boolean first = true;
    
  try
  {
    while (c != null)
    {
      int mod = c.getModifiers();
      
      if (Modifier.isAbstract(mod) || Modifier.isInterface(mod))
      {
        break;
      }
      
      if (first)
      {
        first = false;
      }
      else 
      {
        sb.append(", ");
      }
      
      Object o = c.getConstructor(new Class[] {}).newInstance(new Object[] {});
      sb.append(c.getMethod("getDescription").invoke(
          o, new Object[] {}));
      c = c.getSuperclass();
    }
  }
  catch (Exception e)
  {
    //do nothing
  }
  
  return sb.toString();
}

Twitchy
May 27, 2005

Save the whales posted:

I think I've got it! At least, this solution appears to work. I avoid the problem of the method being overwritten by declaring new instances of the super classes and abandoning recursion.

I actually thought of something like that aswell, whether it's usable depends on how often it'll be called, and any memory restrictions etc, since it's hacked together code. Another option would be to make the getDescription() static, since it looks like the value would be a constant anyway. It would also mean you wouldn't clutter up space with immediately discared objects. Just food for thought. That would have to be a stated requirement though, so if it wasn't implemented it could cause trouble.

Twitchy fucked around with this message at 00:18 on Apr 25, 2008

CrusaderSean
Jun 10, 2002
AwakenedDreamer
Alright, apparently I don't understand how primitives and objects are passed to methods in Java. I thought Java only passes values to methods. But if I pass in an object like array, the object's content will change. For example:

code:
public class SimpleClass {
	void scaleLine(int[] l, int s) {
		s = 40;
		l[0] *= s; l[1] *= s;
	}
	
	public static void main(String[] args) {
		int scale = 1;
		int[] line = new int[2];
		line[0] = 1; line[1] = 2;
		System.out.println("scale="+scale+"; Line="+line[0]+","+line[1]);
		
		SimpleClass sc = new SimpleClass();
		sc.scaleLine(line, scale);
		System.out.println("scale="+scale+"; Line="+line[0]+","+line[1]);
	}
}
notice the scaleLine method doesn't return anything, so I figured nothing will change. but the corresponding output is:
code:
scale=1; Line=1,2
scale=1; Line=40,80
so the primitive int scale did not change value, but the array int[] line did. Does this mean objects are passed in as reference by default? Or am I totally missing something here?

Save the whales
Aug 31, 2004

by T. Finn

Twitchy posted:

I actually thought of something like that aswell, whether it's usable depends on how often it'll be called, and any memory restrictions etc, since it's hacked together code. Another option would be to make the getDescription() static, since it looks like the value would be a constant anyway. It would also mean you wouldn't clutter up space with immediately discared objects. Just food for thought.

Yeah, it's not the greatest solution but it fits my specific needs. The "getDescription" method isn't static but it returns a static value. I wish I could make it static but unfortunately that method I'm overwriting wasn't originally written by me. It's in that code base used by my company in all of our projects, and I can't go changing that now. Luckily, it happens that the constructors for these things are extremely cheap (they're empty).

Thanks for your help, Twitchy.

Twitchy
May 27, 2005

CrusaderSean posted:

Alright, apparently I don't understand how primitives and objects are passed to methods in Java. I thought Java only passes values to methods. But if I pass in an object like array, the object's content will change. For example:

Arrays are themselves Objects, and so are passed by reference. The array may contain primitives (ints, doubles etc), but the structure that holds them is an Object.

Twitchy fucked around with this message at 00:27 on Apr 25, 2008

CrusaderSean
Jun 10, 2002
AwakenedDreamer

Twitchy posted:

Arrays are themselves Objects, and so are passed by reference. The array may contain primitives (ints, doubles etc), but the structure that holds them is an Object.

but if I change the scaleLine method to the following, the line array doesn't change... so if object parameters are really passed in as reference, shouldn't it point to the new int[] newLine? or is the following code just changing where the reference variable is pointing to and has no effect on the caller? :confused:
code:
	void scaleLine2(int[] l, int s) {
		s = 40;
		int[] newLine = new int[2];
		newLine[0] = -2; newLine[1] = -2;
		
		l = newLine;
	}
edit: ah, k. that makes sense. thanks Twitchy

CrusaderSean fucked around with this message at 00:39 on Apr 25, 2008

Twitchy
May 27, 2005

CrusaderSean posted:

but if I change the scaleLine method to the following, the line array doesn't change... so if object parameters are really passed in as reference, shouldn't it point to the new int[] newLine?
code:
	void scaleLine2(int[] l, int s) {
		s = 40;
		int[] newLine = new int[2];
		newLine[0] = -2; newLine[1] = -2;
		
		l = newLine;
	}

Hah, I think this same question was just asked on the last page, and being a master of words made a mess off explaining it, but basically:

When you call scaleLine2, the REFERENCE (i.e. a place in memory where the object can be found) of l in the main method is assigned to a new variable called l. So when you say "l = newLine" you're basically saying "forget that last reference I gave you, use this one instead". So now your temporary variable l refers to the new int[] you made, where as l in the main method still refers to the same location as before.

CrusaderSean
Jun 10, 2002
AwakenedDreamer

Twitchy posted:

Hah, I think this same question was just asked on the last page, and being a master of words made a mess off explaining it, but basically:

When you call scaleLine2, the REFERENCE (i.e. a place in memory where the object can be found) of l in the main method is assigned to a new variable called l. So when you say "l = newLine" you're basically saying "forget that last reference I gave you, use this one instead". So now your temporary variable l refers to the new int[] you made, where as l in the main method still refers to the same location as before.

So in terms of programming practice, which of the following is better?

void someMethod(Object obj...) { ... passed in object value may change ... }
or
Object someMethod(Object obj...) { ... explicitly return changed object ... }

I see people using the first one because they want to change multiple objects in a method and can't return multiple objects. But in reality it is not really "void" in the sense that inputs can change in value so it might be misleading. Maybe this is a non-issue and everyone knows how reference works in Java... I was just really confused the first time I saw someone do that.

Incoherence
May 22, 2004

POYO AND TEAR

CrusaderSean posted:

So in terms of programming practice, which of the following is better?

void someMethod(Object obj...) { ... passed in object value may change ... }
or
Object someMethod(Object obj...) { ... explicitly return changed object ... }

I see people using the first one because they want to change multiple objects in a method and can't return multiple objects. But in reality it is not really "void" in the sense that inputs can change in value so it might be misleading. Maybe this is a non-issue and everyone knows how reference works in Java... I was just really confused the first time I saw someone do that.
void simply means there's no return type; it doesn't mean that nothing will be modified. In general, Java's "we're hiding pointers from you but they're still there!" semantic is something you trip over once then learn.

Drumstick
Jun 20, 2006
Lord of cacti
ahhhh! quick question

How can I add 2 things into the same JFrame!

Both will work seperately, but when I try and add both in at the same time one will overwrite the other. im hoping this will be something somewhat simple.

quote:


JFrame frame = new JFrame();
frame.add(component);
frame.add(component2);


Component2 will show, but component wont show up at all. By themeselves, they will be up and working just fine, just not together...

Drumstick fucked around with this message at 06:59 on Apr 25, 2008

zootm
Aug 8, 2006

We used to be better friends.

Drumstick posted:

Component2 will show, but component wont show up at all. By themeselves, they will be up and working just fine, just not together...
Swing works with layout managers for components, and I think the default one just holds one item. I think reading up on layout in Swing might be your best course of action here.

With some layouts you need to pass the "position" where the item should appear as well - with BorderLayout you can choose NORTH, SOUTH, EAST, WEST, or CENTER, for example.

Drumstick
Jun 20, 2006
Lord of cacti
okay thanks! i will look into that right away. I havent had to add two components into a frame before, thanks again

zootm
Aug 8, 2006

We used to be better friends.

Drumstick posted:

okay thanks! i will look into that right away. I havent had to add two components into a frame before, thanks again
Here's the Sun tutorial, this section concerns layout. If you're hand-cranking Swing you probably wanna skip the stuff about the NetBeans UI designer in the overall trail, which is very nice but insulates you pretty much entirely from the layout code.

PianoDragn
Jan 30, 2006
* IMPORTANT: Performance is very important, please make the method efficient *

I am making an app right now and could use the following Graphics2D wrapper methods (I don't know a thing about Graphics2D)

1.) I want a method called applyOpacity(Image,Double) where it accepts an Image type and a double specifying the opacity. It will then use Graphics2D to apply the opacity to the Image and return the new Image. I don't know if this is possible or not, if it can't be stored in an image and instead needs to be stored in a Graphics object then return that instead.

2.) applyLighting(Image,Int) I send it an image with a brightness 0 being completely black and 100 being completely white? It then returns the resulting Image.

The useage would be if I wanted to bring something ot the foreground I would draw my background on offscreen image, pass it to the lighting method and darken it. Then I would take my 2nd image thats foreground send it to opacity and drawImage onto the offscreen image.

Thanks!

Twitchy
May 27, 2005

PianoDragn posted:

* IMPORTANT: Performance is very important, please make the method efficient *

I am making an app right now and could use the following Graphics2D wrapper methods (I don't know a thing about Graphics2D)

1.) I want a method called applyOpacity(Image,Double) where it accepts an Image type and a double specifying the opacity. It will then use Graphics2D to apply the opacity to the Image and return the new Image. I don't know if this is possible or not, if it can't be stored in an image and instead needs to be stored in a Graphics object then return that instead.

2.) applyLighting(Image,Int) I send it an image with a brightness 0 being completely black and 100 being completely white? It then returns the resulting Image.

The useage would be if I wanted to bring something ot the foreground I would draw my background on offscreen image, pass it to the lighting method and darken it. Then I would take my 2nd image thats foreground send it to opacity and drawImage onto the offscreen image.

Thanks!

I have no idea of the performance of this method, but this is how I got it working:

code:
public Image applyOpacity(Image img, double opacity) {
    int w = img.getWidth(null);
    int h = img.getHeight(null);

    float[] scales = { 1f, 1f, 1f, (float)opacity };
    float[] offsets = new float[4];

    RescaleOp rop = new RescaleOp(scales, offsets, null);

    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = (Graphics2D)bi.getGraphics();

    BufferedImage temp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    temp.getGraphics().drawImage(img, 0, 0, null);

    g2d.drawImage(temp, rop, 0, 0);
	
    return bi;
}
You'd be better off using a float to determine the opacity since that is what the RescaleOp uses, but since you said double I just cast it to that anyway. You could also edit the parameters to include light / darkness aswell I believe, using the scales array. Originally I had an "if (img instanceof BufferedImage)" to save on having the temp BufferedImage but I got the following error:

code:
Number of scaling constants does not equal the number of of color or color/alpha  components
Anybody know why it throws that? Playing around with images has never been my strong suit.
There's more info on this kind of method here: http://java.sun.com/docs/books/tutorial/2d/images/drawimage.html

Twitchy fucked around with this message at 17:02 on Apr 25, 2008

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm looking to implement some charts on a Java web application. Right now I'm reading about JFreeChart. What are some others worth looking into? I'd prefer to go down either the static images route or possibly flash based for some user interaction, no applet type stuff.

fletcher fucked around with this message at 23:58 on Apr 25, 2008

ynef
Jun 12, 2002

fletcher posted:

I'm looking to implement some charts on a Java web application. Right now I'm reading about JFreeChart. What are some others worth looking into? I'd prefer to go down either the static images route or possibly flash based for some user interaction, no applet type stuff.

Tow questions: what kind of charts, and can you run other programs on your server as well? Such as, for instance, gnuplot? Just asking. Also, since it's web, I'm guessing you want to output at least PNG or something (perhaps have support for PDF and PostScript as well)? More specs, please. :)

ynef
Jun 12, 2002

PianoDragn posted:

* IMPORTANT: Performance is very important, please make the method efficient *

I am making an app right now and could use the following Graphics2D wrapper methods (I don't know a thing about Graphics2D)

1.) I want a method called applyOpacity(Image,Double) where it accepts an Image type and a double specifying the opacity. It will then use Graphics2D to apply the opacity to the Image and return the new Image. I don't know if this is possible or not, if it can't be stored in an image and instead needs to be stored in a Graphics object then return that instead.

2.) applyLighting(Image,Int) I send it an image with a brightness 0 being completely black and 100 being completely white? It then returns the resulting Image.

The useage would be if I wanted to bring something ot the foreground I would draw my background on offscreen image, pass it to the lighting method and darken it. Then I would take my 2nd image thats foreground send it to opacity and drawImage onto the offscreen image.

Thanks!

Read up on VolatileImage, it is supposedly faster and stored in video RAM (according to this). Perhaps that could speed things up for you?

Heisenberg1276
Apr 13, 2007
Does anyone know of good resources to learn hot to use Project Darkstar (Sun Game Server) as the things I can find on the official site seems pretty confusing.

CrusaderSean
Jun 10, 2002
AwakenedDreamer
I'm playing with java.util.Observer and Observable for MVC GUI design. I don't really understand how the listener/observers determine if the state has changed. I know you can run dataModel.hasChanged() to explicitly mark the data state as changed, but when is it necessary to do this? Does java automatically mark observable state as changed or do I have to do it manually?

I redid this simple temperature program here. So when the temperature is raised or lowered, the GUI will call setTemperature function in the model. The model's setTemp function will in turn call the notifyObserver function. The temperature model does not call hasChanged() at all and it works just fine. So Java must have determined temperature state has changed somehow...

Then I created my own example with a more complicated data structure. I'm using the same basic concept for observer and observable. I tried the following two variations:

case 1:
update state parameters, run notifyObserver => observer.update() doesn't run and nothing changes

case 2:
update state parameters AND set model.hasChanged(), run notifyObserver => will run observer.update() and GUI will reflect changes

So does this mean I need to set model.hasChanged() manually for more complicated data models?

CrusaderSean fucked around with this message at 03:25 on Apr 29, 2008

the onion wizard
Apr 14, 2004

CrusaderSean posted:

The temperature model does not call hasChanged() at all and it works just fine.

No, but is does call setChanged(), which means that any subsequent calls to hasChanged() will return true until clearChanged() is called.

Observable API posted:

public void notifyObservers(Object arg)

If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

Edit: To clarify, for now, you probably want to call setChanged before every call to notifyObservers.

the onion wizard fucked around with this message at 10:09 on Apr 29, 2008

CrusaderSean
Jun 10, 2002
AwakenedDreamer

triplekungfu posted:

No, but is does call setChanged(), which means that any subsequent calls to hasChanged() will return true until clearChanged() is called.


Edit: To clarify, for now, you probably want to call setChanged before every call to notifyObservers.

Hmm.. how did I miss that setChanged() line.. thanks for the clarification.

edit: actually I was using setChanged(), I guess I'm illiterate that late in the night...

CrusaderSean fucked around with this message at 16:11 on Apr 29, 2008

Cubiks
Aug 31, 2005
I wish I had something witty to put here...
Okay, I have a question similar to the MultiMap one last page. I have a grid of devices laid out, with each device taking up (possibly) several grid cells, and in addition devices can be layered so that there are several on a single cell. I want to be able to go from a cell to the devices on said cell, and from a device to all cells covered by that device. Is there anything better than just using two HashMaps/MultiMaps for this, one for each direction?

Heisenberg1276
Apr 13, 2007
I am making an application and need it to be skinnable, to the extent that someone could add extra JTextFields to the form for extra inputs. Much of the code is in javascript using mozilla rhino so this will need to be able to access the extra JTextFields to work with the input.

What would be my best option for this? I've looked into SwiXML but couldn't get far because for some reason I can't get it to build on OSX, before I mess around with it to get it to build I want to know if there are any better options?

hey mom its 420
May 12, 2007

The other day I was thinking, is there any reason why Java doesn't have return type polymoprhism? I mean like having public String foo() and public int foo() and then the one that gets called depends on what kind of type of return value the caller expects. This works really nicely in languages like Haskell and I see nothing in Java that prevents it form having this feature.

zootm
Aug 8, 2006

We used to be better friends.

Bonus posted:

The other day I was thinking, is there any reason why Java doesn't have return type polymoprhism? I mean like having public String foo() and public int foo() and then the one that gets called depends on what kind of type of return value the caller expects. This works really nicely in languages like Haskell and I see nothing in Java that prevents it form having this feature.
Because of polymorphism of types this would reduce the obviousness of the return type. For example given:
code:
public String foo();
public StringBuilder foo();
What would the following do?:
code:
Object bar = foo();
You could use something similar to the generic method disambiguation stuff but it would be a fairly huge new language feature:
code:
Object bar = this.[String]foo();
One would need to have language syntax for explicitly expressing which one of the functions one is calling, which would make Java even more verbose (and in cases where it could guess the type, arguably more difficult to read), for very little actual expressive benefit. Essentially this works in Haskell because the type system is so much stronger.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
FYI, the JVM has no such restriction on overloaded return types. Only the JLS does. You can do this in Jaskell and possilby Scala, IIRC.

zootm
Aug 8, 2006

We used to be better friends.
I'm fairly sure you cannot do this in Scala, for what it's worth. I'll have a look tonight if I remember though.

Also the fact that you can do it in Jaskell does not mean that the bytecode or the JVM supports it directly. A lot of JVM languages encode such concepts (the multiple inheritance in Scala, for example, is not something that JVM bytecode supports directly).

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

zootm posted:

I'm fairly sure you cannot do this in Scala, for what it's worth. I'll have a look tonight if I remember though.

Also the fact that you can do it in Jaskell does not mean that the bytecode or the JVM supports it directly. A lot of JVM languages encode such concepts (the multiple inheritance in Scala, for example, is not something that JVM bytecode supports directly).

I understand what you mean, but the JVM docs specifically state that it does not restrict overloaded method returns.

zootm
Aug 8, 2006

We used to be better friends.

TRex EaterofCars posted:

I understand what you mean, but the JVM docs specifically state that it does not restrict overloaded method returns.
Cool, just checking. Is that how Jaskell works? It seems strange to have a JVM language that Java can't call.

Adbot
ADBOT LOVES YOU

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

zootm posted:

Cool, just checking. Is that how Jaskell works? It seems strange to have a JVM language that Java can't call.

I actually do not know how Jaskell is implemented. I kinda wrote that post quickly and should have put the word "also" in there somewhere. :p

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply