Browsing 7239 questions and answers with Jon Skeet

Can Not Access Static Class Function?

Here is my Code static class NativeMethods { [DllImport("kernel32.dll")] public static extern IntPtr LoadLibrary(string dllToLoad); [DllImport("kernel32.dll")] ...
Jon Skeet
people
quotationmark

Why can't I initialize my variable "pDll"? The compiler is telling you exactly why - you can't access instance fields within an instance field initializer. It looks like these should probably be static anyway: static readonly string... more 8/25/2015 2:13:29 PM

people

Java8 method reference used as Function object to combine functions

Is there a way in Java8 to use a method reference as a Function object to use its methods, something like: Stream.of("ciao", "hola", "hello") .map(String::length.andThen(n...
Jon Skeet
people
quotationmark

You can write a static method to do this: import java.util.function.*; class Test { public static void main(String[] args) { Function<String, Integer> function = combine(String::length, n -> n * 2); ... more 8/25/2015 2:08:09 PM

people

Google cloud storage namespace

I'm trying to upload file to my storage. I use this code String serviceAccountEmail = "YOUR SERVICE EMAIL HERE"; var certificate = new X509Certificate2(@"PATH TO YOUR p12 FILE...
Jon Skeet
people
quotationmark

It looks like you're missing a NuGet package - you should install the Google.Apis.Storage.v1 package in your project. After that, you should be able to add a using directive of using Google.Apis.Storage.v1; ... and use code of: var... more 8/25/2015 11:42:59 AM

people

JMeter Static method get( java.lang.String ) not found in class'java.nio.file.Paths'

I am trying to create a JMeter load test. I need the test to take a sample log file and change its name. The only way I could find to do this was to copy the file in a BeanShell...
Jon Skeet
people
quotationmark

My guess is that the problem is that it's not populating the varargs parameter. Try: Path target = Paths.get(filename, new String[0]); more 8/25/2015 10:55:34 AM

people

Overflow exception is throwing even the value exceeds the limit

Why the following code Gives output as -2 instead for throwing overflow exception? long x = long.MaxValue; long y = long.MaxValue + x;
Jon Skeet
people
quotationmark

Presumably because you're executing it in an unchecked context. Arithmetic on the primitive integer types can execute in a checked or unchecked context. Operations which overflow throw an exception in a checked context, and just use the... more 8/25/2015 10:41:13 AM

people

EOFException on opening a buffered object stream

I'm testing the ObjectInputStream and ObjectOutputStream classes tried to warp both in buffered stream object .. File file = new File("file.lel"); //Assuming the file exist and...
Jon Skeet
people
quotationmark

Firstly, don't do this. Don't try to initialize the input stream until you've got data in the file. As for why it's working when you don't buffer, I believe the problem is with the buffering of the output stream... in the buffered... more 8/25/2015 6:11:16 AM

people

select query does not work with parameters using Parameters.AddWithValue

The following query in C# doesn't work, but I can't see the problem: string Getquery = "select * from user_tbl where emp_id=@emp_id and...
Jon Skeet
people
quotationmark

I'll assume your code is actually not quite as presented, given that it wouldn't currently compile - you're using cmdR before you declare it. First, you're trying to use named parameters, and according to the documentation of... more 8/25/2015 5:56:13 AM

people

How to model HashMap/Dictionary in the ProtoBuf efficiently

I have a protobuf file serialized by .NET code and I would like to consume it into Java. In the .NET code, there is Dictionary data type and the proto schema looks like message...
Jon Skeet
people
quotationmark

Well, maps are already supported in "protobuf proper" as of v3.0. For example, your proto is effectively: message Dictionary { map<string, string> pairs = 1; } The good news is that with the key and value fields you've... more 8/24/2015 4:36:01 PM

people

What is the difference between using \u and \x while representing character literal

I have seen \u and \x used interchangeably in some places while representing a character literal. For example '\u00A9' == '\x00A9' evaluates to true Aren't we supposed to use...
Jon Skeet
people
quotationmark

I would strongly recommend only using \u, as it's much less error-prone. \x consumes 1-4 characters, so long as they're hex digits - whereas \u must always be followed by 4 hex digits. From the C# 5 specification, section 2.4.4.4, the... more 8/24/2015 6:13:36 AM

people

How can I change the timezone of a date string?

I would like to change the timezone of a time like: 2015-08-24 01:30:40 so that it's in the America/Los_Angeles timezone, but the code below isn't working as...
Jon Skeet
people
quotationmark

Your call to date_create_from_format includes an A at the end of the format string - that looks specious to me, given that your value doesn't end with am or pm. Your use of h looks unlikely to be correct too, as that's for a 12-hour... more 8/24/2015 6:08:49 AM

people