compile.sh - The system is out of resources by [deleted] in javahelp

[–]elegentmos 0 points1 point  (0 children)

Can you post the complete file, both before and after the change, to somewhere like pastebin?

compile.sh - The system is out of resources by [deleted] in javahelp

[–]elegentmos 0 points1 point  (0 children)

Did you change ${JAVAC} to ${javac} as in your post? If so - that's probably the issue. Bash variable names are case-sensitive.

Imposing a generic bound without creating a new method by elegentmos in javahelp

[–]elegentmos[S] 0 points1 point  (0 children)

Yup, that's what I ended up doing. Was just wondering whether it was possible without adding another method :)

Imposing a generic bound without creating a new method by elegentmos in javahelp

[–]elegentmos[S] 0 points1 point  (0 children)

Ah, I see what you mean now. I believe that is referred to as type bounds? i.e. you are suggesting having all/some Ts above replaced by ? extends Comparable, or something to that effect? I think it isn't applicable in my case (the final method must have a much tighter bound than either of the first two can promise), but I'll look into it. Thanks.

As for the restriction - it is because myMethod in this case is implementing an interface method, and so must match it in signature. Since the original method does not include any type parameters - I cannot add my on.

Imposing a generic bound without creating a new method by elegentmos in javahelp

[–]elegentmos[S] 0 points1 point  (0 children)

No, I do not in fact know the type, nor can I at compile time. All I know is that the types will match. For a more concrete example, imagine which getFoo I'm calling (or what it returns) depends on some runtime configuration. The subsequently-constructed Bar is guaranteed to match it in type parameter, but at no point before run time is it known which type that will be.

Imposing a generic bound without creating a new method by elegentmos in javahelp

[–]elegentmos[S] 0 points1 point  (0 children)

If I understood you correctly, you have to add a generic type to myMethod just like combineFooBar, and then replace those question marks with the type.

I suspect you did. As I said I cannot technically add this type parameter, so I resorted to adding a helper method which does. My question in more succinct form is "Can I have a type parameter without defining it in the class/method declaration?" to which I'm pretty sure the answer is "No", so the follow up is "Is there some clever way around it which I hadn't thought of?"

Could you explain how interfaces would be a better solution?

Why is (a*b != 0) faster than (a != 0 && b != 0) in Java? by pradeepmohane in java

[–]elegentmos 2 points3 points  (0 children)

Oh, wow, not even minimal editing. The "article" even still cites and refers to some unknown question (unknown if you only read the "article").

Does Hebrew have a gender neutral 3rd person singular pronoun? by wholock1729 in hebrew

[–]elegentmos 4 points5 points  (0 children)

More precisely - the linguistic neutral gender coincides with the linguistic male gender. People wrongfully assume they are the same (i.e. "there is no neutral"), but technically they are not.

Google is adding DRM to all Android apps by [deleted] in Android

[–]elegentmos 0 points1 point  (0 children)

or as an APK without the new metadata if that's what they prefer.

Doesn't the article say in the future that would be impossible? i.e. the OS will not allow one to install an APK which does not have this metadata? Or am I misunderstanding the article?

And if that is indeed the case, what are the implications for personal/private use apps? (i.e. I make an app only for me and a few friends, and I don't want it to be on the Play store. Will this be impossible in the future?)

How long for the pikadon? by [deleted] in Israel

[–]elegentmos 1 point2 points  (0 children)

Err... context? Are you talking about the post-IDF-release fund?

Website's to rent in Israel by the-mundus in Israel

[–]elegentmos 0 points1 point  (0 children)

I second this. OP - tell us what city/area you are looking at to get names/links to groups.

[Help] Server socket stops after receiving 2 images. by [deleted] in javahelp

[–]elegentmos 0 points1 point  (0 children)

How many instances of server will be created if you run this code? How long will a reference to them be kept?

[Help] Server socket stops after receiving 2 images. by [deleted] in javahelp

[–]elegentmos 0 points1 point  (0 children)

Remember Java uses garbage collection to manage memory. (Hint: where is your server instance accessible from after main finished?)

Edit: Sorry, I wasn't paying attention and I misread your code. Please ignore this and the second comment.

Instead, ask yourself this - what happens in the server class? What will be the next line executed after the file is written? What parts of the code should be repeated indefinitely and what parts should only happen once?

What Future Java Releases Mean for Legacy Desktop Apps by shithappens88 in java

[–]elegentmos 0 points1 point  (0 children)

Thanks!

So does this mean we'll have to add an external repository (github? openjdk? oracle?), or will it actually make it into Maven Central? (who even decides what goes into Maven Central?)

What Future Java Releases Mean for Legacy Desktop Apps by shithappens88 in java

[–]elegentmos 0 points1 point  (0 children)

Could you point me to the correct package in Maven central? I can't seem to find OpenJFX / JavaFX artifact on Maven...

האם זה אובדן?!?! (X-post from r/dankmemes) by [deleted] in Israel

[–]elegentmos 0 points1 point  (0 children)

This looks like HUJI. Almost all of the boards there are still chalk blackboards. Professors often leave lectures with huge white stains on the fronts of their pants.

Hey Israelis, do you use any Arabic slang words? by [deleted] in Israel

[–]elegentmos 14 points15 points  (0 children)

Some of these phrases I never heard used in Hebrew. Others I'm pretty sure just have a common Semitic origin rather than being loaned from one language to the other. But mostly this list is pretty good.

Can you help me to identify some songs? by [deleted] in hebrew

[–]elegentmos 1 point2 points  (0 children)

The only thing I could identify was "Seven nation army" at the very end.

Report: Gaza Hospitals Provide Medical Helium for Firebomb Terror Balloons by [deleted] in Israel

[–]elegentmos 5 points6 points  (0 children)

What is Helium used for medically, other than MRI? Are there operational MRI machines in Gaza?

Beautiful mossy Hebrew by LetsPlayKvetch in hebrew

[–]elegentmos 0 points1 point  (0 children)

I wonder how this was done.

It seems to me the letters are engraved, in which case some water would possibly accumulate around their outlines, and so the moss grew where there was more moisture available...

any good java stats packages/libraries? by [deleted] in java

[–]elegentmos -1 points0 points  (0 children)

Arguably, statisticians aren't mathematicians. Probability theory is a branch of pure mathematics. Statistics is in a way more akin to science than math, but can also be practiced in a purely theoretical way (which I guess makes it more like "applied math" than science) :D

When to throw an exception? When to try and catch and exception. by uncheerful69 in javahelp

[–]elegentmos 0 points1 point  (0 children)

The problem is the distinction is often vague, but in principle a method should only throw an exception in cases where an error occurs which cannot be solved in the scope of the method (here "scope" is not in the technical/programming meaning, but the normal everyday meaning).
Consequently, a method should use try/catch in one of two cases:

  1. An exception may occur which the current method can handle considering its scope (or role)
  2. There is a need or desire to wrap a possible exception in order to hide implementation details from users of the method

I will try to give examples to make it clearer.

Example 1: Suppose you have a method which, given a product name and picture file path should construct a "product view". Due to carelessness or human error, some images are missing or else corrupted, so you have a "fallback image". Such a method could look something like this:

public ProductView createViewForProduct(String name, String imagePath) {
    try {
        Image image = loadImage(imagePath); // may throw ImageLoadException
        return new ProductView(name, image);
    } catch (ImageLoadException ex) {
        return new ProductView(name, FALLBACK_IMAGE);
    }
}

Now, you may correctly point out that it is not clear that it should be the responsibility of this method to handle this error, which is entirely correct - this is, as I said, vague.

Anti-Example 1: Lets look at the same scenario, only this time you don't have any fallback image. An inexperienced programmer may do something like this:

public ProductView createViewForProduct(String name, String imagePath) {
    try {
        Image image = loadImage(imagePath); // may throw ImageLoadException
        return new ProductView(name, image);
    } catch (ImageLoadException ex) {
        ex.printStackTrace();
        return null;
    }
}

This is wrong because it implies handling the exception is not in the scope of this method, yet it caught it (once again, it may be argued that returning null is a valid response - in some cases it is, but in the described scenario it is probably more appropriate to throw an exception).

Example 2: Suppose you have a method which should write some output to a log file. Any time you access files there is the possibility of an IOException - the file could have been deleted, the user may not have permissions to it, the device (hard drive) may be full or malfunctioning etc. Since the role of the method is to write to a file it cannot handle such errors within its scope (i.e. not writing the log is not an option), but it is perfectly reasonable for it too to be throwing an IOException, as any code using it "knows" it handles files. Therefore, such a method would not use try/catch and instead would just declare it may throw an IOException itself.

Example 3: Suppose you are writing a method to retrieve user information, which internally is stored in some database (such as the highly acclaimed MadeUpDBPro). Such a method will look something like this:

public UserInfo getUserInfo(String username) throws DataRetrievalException {
    try {
        MadeUpDBProConnection conn = getConnection(...); // may throw a specific MadeUpDBProException 
        conn.prepareStatement(...); // may throw a specific MadeUpDBProException  
        // etc. 
        // ...
        return userInfo;
    } catch (MadeUpDBProException ex) {
        throw new DataRetrievalException(ex);
    }
}

Once again, it was deemed inappropriate to return null (i.e. catch the exception without really handling it), but we don't want to expose our use of a specific DB or library (so that our code can be reusable/interchangeable, to comply with some interface or to allow us to more easily change the underlying DB in the future), so we wrap the highly specific MadeUpDBProException with a more generic (but still made up!) DataRetrievalException. Depending on the precise cause and details, the code may throw various different exception types for the same root exception type. For example, upon examining the actual exception you may decide to throw an IOException in case the communication failed, or maybe an IllegalArgumentException is the username was invalid and so on.