Browsing 7239 questions and answers with Jon Skeet

Extending the main class in Java

I need to extend the functionality of my main class, by overriding some of its methods. I was expecting that the class extending the main class would be able to be run. However,...
Jon Skeet
people
quotationmark

As you say, the fact that you create an instance of Launcher directly in main means that no inheritance is available. Even if you could start MyLauncher easily from Eclipse, within the main method you wouldn't know which type had actually... more 5/14/2014 1:46:56 PM

people

How to convert an int to byte while keeping order

I am working with Local Binary Patterns (LBP) which produce numbers in the range 0-255. That means that they can fit in a byte (256 different values may be included into a byte)....
Jon Skeet
people
quotationmark

You could subtract 128 from the value: byte x = (byte) (value - 128); That would be order-preserving, and reversible later by simply adding 128 again. Be careful to make sure you do add 128 later on though... It's as simple as: int... more 5/14/2014 12:06:31 PM

people

What exactly is the use of event handler accessors/properties?

I have an interface with the line: event EventHandler<MagazineEventArgs> MagazineChangedEvent; When I implement the interface, Visual Studio generates the following...
Jon Skeet
people
quotationmark

Often, you can just use a field-like event, e.g. just declare: public event EventHandler<MagazineEventArgs> MagazineChangedEvent; That's roughly equivalent to declaring a private delegate field and accessors which subscribe to it... more 5/14/2014 11:55:11 AM

people

What's happening inside this method?

I can't quite figure out what's happening inside this method when I call it with 2 as argument. public int foo(int i) { if (i > 0) { System.out.println(”i: ” +...
Jon Skeet
people
quotationmark

What I don't understand here is where the second value of i which is 1 come from. Regardless of whether or not the method recurses, it always returns i. So a call of foo(2) will always return 2, even though it recurses while... more 5/14/2014 9:54:02 AM

people

Using Getters and Setters in Unity

I have another question about this with getters and setters. Now that I started working with c# getters and setters as I understood them. The problem I see is that why should I...
Jon Skeet
people
quotationmark

I don't see the point of that since what different would it then be to just make the variable public since it's anyway got the get and set in the same bracket? The difference is that you're separating your implementation detail (a... more 5/14/2014 8:52:37 AM

people

Cannot implicitly convert type 'System.Collections.Generic.List<System.Collections.Generic.IEnumerable<xxx>>' to 'System.Collections.Generic.List<xxx>

I am getting the following error. I googled it for more than a day but I cant find the exact solution, Please help me Thank you ERROR: Cannot implicitly convert type ...
Jon Skeet
people
quotationmark

The problem is that at the moment, you're selecting a sequence of sequences - one sequence of ShareholderUser items for each Shareholder. If you just want a list of ShareholderUser items, you need to flatten the results. That's most easily... more 5/14/2014 6:17:49 AM

people

attempting to assign weaker access privileges; was public error for isCancelled

So i have this code for isCancelled in SwingWorker boolean isCancelled() return true; and its giving me the error attempting to assign weaker access privileges; was...
Jon Skeet
people
quotationmark

Firstly, you need braces around your method body. Secondly, the way you're currently declaring it uses package access, but the isCancelled method is public, so you'd have to override it with another public method. Thirdly, the method is... more 5/14/2014 5:54:45 AM

people

Can you hack system.out.println() on a jar file?

I have an executable jar file. The java code contains a lot of System.out.println statements. Sometimes, these print statements contain passwords and stuff like that. I have...
Jon Skeet
people
quotationmark

Absolutely - they can start your app from the command line rather than by double-clicking on the jar file, and any console output will be shown. Alternatively, they could write their own wrapper class which redirected System.out to a... more 5/13/2014 6:13:54 PM

people

why NodaTime do not support some countries?

i used "NodaTime.dll, v1.2.0.0" in my site to calculate time zone i use this code to retrieve ZonedId: var tempInfo = (from location in...
Jon Skeet
people
quotationmark

This is really just a matter of the data which is in CLDR and TZDB. (As it happens, I'm in the middle of updating to the CLDR v25 mapping data.) The UK is present using its ISO-3166 code of "GB". The ISO-3166 code for Ascension Island is... more 5/13/2014 5:59:43 PM

people

NoClassDefFoundError on Android

I have no idea what I am doing wrong. I want to create a path variable in my Android project, but everytime I get a NoClassDefFoundError. test = test + ".turns"; //This is a...
Jon Skeet
people
quotationmark

You're trying to use java.nio.file.Paths, which doesn't exist in Android as far as I can see. (Only some parts of the Java 7 API are supported.) It's not clear what path you're looking for, or what you're going to do with the result, but... more 5/13/2014 5:48:24 PM

people