Browsing 7239 questions and answers with Jon Skeet

assigning int literal to Long in java

I see no clear rationale for happening this .. public class wrappers { public static void main(String []args) { short s1=32767; // (primitive) works fine without...
Jon Skeet
people
quotationmark

are there any rules governing these wrapper classes' assignments Yes - the rules of the JLS. It specifies widening primitive conversions (5.1.2) and boxing conversions (5.1.7). The list of boxing conversions includes: From... more 6/23/2016 6:27:40 AM

people

How to get method name from inside that method without using reflection in C#

I want get the method name from inside itself. This can be done using reflection as shown below. But, I want to get that without using...
Jon Skeet
people
quotationmark

From C# 5 onwards you can get the compiler to fill it in for you, like this: using System.Runtime.CompilerServices; public static class Helpers { public static string GetCallerName([CallerMemberName] caller = null) { ... more 6/23/2016 6:04:15 AM

people

C#: get the value of a key in an object using regex

I have a key with random bits of string in it making it difficult to extract it's value. How would I go about doing it when I don't know the random bits ahead of time? given:...
Jon Skeet
people
quotationmark

Use LINQ to JSON instead. If you parse it as a JObject, you can iterate over all the properties, and find those which match your regex. Regex regex = new Regex(...); JObject json = JObject.Parse(text); foreach (var property in... more 6/23/2016 5:57:33 AM

people

How can I get the start and end time of a period?

I have an enum TimeFrame that has values like: Yesterday, LastWeek, NextMonth etc. I'm trying to write a method that takes in a TimeFrame and returns the start and end dates of...
Jon Skeet
people
quotationmark

No, a Period doesn't record a start/end - it just represents the amount of time between them, in a calendrical sense (rather than the "precise amount of time" represented by a Duration). It sounds like basically you should create your own... more 6/22/2016 5:50:13 PM

people

how to create a .net core class library

I am new to .net core. I need some help to configure my project.json file to create a class library with .net core. I actually read a lot of documents, but I am lost since there...
Jon Skeet
people
quotationmark

Your class library itself should have a framework of netstandard1.3 or whatever version you want - Noda Time is targeting netstandard1.3 for example, as I've found that there's too much missing from netstandard1.0, unfortunately. I'd... more 6/22/2016 4:00:36 PM

people

Java cannot find symbol for class in another java file but in the same directory

I am a beginner in learning java, and I am using notepad to learn my basics in java and I can't seem to use the class that I have in another java file(but in the same directory),...
Jon Skeet
people
quotationmark

Your Tetrominoes enum is nested in Shape. So you could refer to it as: private Shape.Tetronminos[] board; ... but you'd be better off promoting it to a top-level type, in my view. I'd also suggest calling it Tetromino (singular) and... more 6/22/2016 8:46:07 AM

people

Issue with rounding mode in ROUND_UP in Java

I want to use ROUND_UP as the rounding mode. But, when the decimals in the original number are less than three decimals, then at the end "1" is appended. int precision = 3; ...
Jon Skeet
people
quotationmark

But, when the decimals in the original number is less than 3 decimals, then at the end "1" is appended. Your value of 2.04 isn't really 2.04. It's actually 2.04000000000000003552713678800500929355621337890625, which is the double... more 6/22/2016 8:26:35 AM

people

How to unit test explicit interface implemented methods?

I have the following method in a service but I'm failing to call it in my unit test. The method uses the async/ await code but also (and which I think is causing me the problem)...
Jon Skeet
people
quotationmark

Yes, explicit interface implementations can only be invoked on an expression of the interface type, not the implementing type. Just cast the service to the interface type first, or use a different variable: [Fact] public async Task... more 6/21/2016 3:50:44 PM

people

Unity3D Call Static method from Android

I created simple plugin for opening Android Activity from Unity3D. Have problem to trigger method with parameters. Any ideas? Java Code public static void Show(Activity...
Jon Skeet
people
quotationmark

You're calling Call, which is meant to call an instance method. You want CallStatic, which calls a static method. more 6/21/2016 6:43:23 AM

people

Parse datetime string gives error on index 21

I have this datestring: 2011-11-01T13:00:00.000 and I don't seem to get that one parsed no matter if I try SimpleDateformat or the DateTimeformatter My last try is this...
Jon Skeet
people
quotationmark

You've specified one digit of subsecond precision - but you've got three. Use SSS and it's fine: String text = "2011-11-01T13:00:00.000"; DateTimeFormatter formatter =... more 6/21/2016 6:33:27 AM

people