Browsing 7239 questions and answers with Jon Skeet

Need Basic Information about Using Reference to an Instance Method of a Particular Object

I'm a moderately experienced C++ guy learning Java. I'm struggling to understand references that "point" to a specific instance of an object. In C++, this would be easy. But...
Jon Skeet
people
quotationmark

At the end of the fight, I'd like a "WinnerReference" reference to "point" to the last boxer standing It sounds like you're looking for pass-by-reference. That doesn't exist in Java - all values are passed by value, but for any... more 11/21/2014 8:52:27 PM

people

Streamreader Directory

I'm working with StreamReader in my Asp.Net mvc application. I'm having an issue getting the StreamReader to use the root of my application, and not the C:// drive on my...
Jon Skeet
people
quotationmark

When you run a web application, the current working directory of the process isn't the directory containing your source code. You might want to look at HttpServerUtility.MapPath or HostingEnvironment.MapPath. Note that this doesn't really... more 11/21/2014 8:39:05 PM

people

Need help making a generic function / interface (C#)

I have some code that is repeated exactly the same for several different data types. I'd like to reduce it to one generic method, but I'm having trouble figuring out how to do...
Jon Skeet
people
quotationmark

It sounds like you should have an abstract base class for the section which has all the repeated code - it's not entirely clear why you need separate types at all, to be honest. You can then have: private List<LinkData>... more 11/21/2014 6:52:51 PM

people

EnumParentAttribute and Intellisense

I have a class with an enum namespace Entities { public partial class OrderStatusType : Entity { public enum EOrderStatusType { P2 = 1, ...
Jon Skeet
people
quotationmark

How can I add a "constarint" that forces me to decorate a new EOrderStatusType item with the custom attribute EnumParent? There is a way to ask to compiler to notify an exception during compile? Two options: Add a unit test. This... more 11/21/2014 5:38:21 PM

people

Unit testing a class with a Java 8 Clock

Java 8 introduced java.time.Clock which can be used as an argument to many other java.time objects, allowing you to inject a real or fake clock into them. For example, I know you...
Jon Skeet
people
quotationmark

I don't want to add a Clock argument to the method because the real code shouldn't be concerned with passing in a clock. No... but you might want to consider it as a constructor parameter. Basically you're saying that your class needs... more 11/21/2014 5:34:08 PM

people

Unchecked call to 'compareTo(T)'

I'm trying to implement a Binary Search Tree, just for the sake of learning, and I want the tree to be generic. This is the code I have so far (very limited): package...
Jon Skeet
people
quotationmark

Comparable<T> is a generic type, but you're using the raw type, losing type safety. You probably want to make your BinNode generic too, in its element type: public class BinNode<T extends Comparable<T>> { private T... more 11/21/2014 4:39:00 PM

people

Getting error on the string im trying to pass to my function call of Createnewfile in main

My only issue is that I get an error where I have commented. Im willing to send my strings (token[]) data at index 1 to the Createnewfile () method in the main. I can't achieve...
Jon Skeet
people
quotationmark

If you're trying to the array reference, just lose the []: Createnewfile(tokens); That's not just passing tokens[1], however. It's very odd that your Createnewfile method always uses tokens[1] - it would make more sense for that... more 11/21/2014 4:32:11 PM

people

How do you await a Task when unit testing?

In a C# testing project, I have this test: [TestMethod] public void TestIfListFilled() { // arrange byte stuffTypeID = 0; List<Stuff> locationList = null; ...
Jon Skeet
people
quotationmark

You can make your unit test async as well: [TestMethod] public async Task TestIfListFilled() { // arrange byte stuffTypeID = 0; // act List<Stuff> locationList = await GetStuffListAsync(stuffTypeID ); //... more 11/21/2014 1:22:07 PM

people

How to create composite .cs file

I need to create one .cs file from all .cs files of the solution(Visual Studio 2012) for some bureaucracy. Is there a plugin that can help me with it?
Jon Skeet
people
quotationmark

That isn't possible, in a general sense. Consider these two files: Foo.cs: #define X #if Y #error Bang! #endif #if !X #error Bang! #endif class Foo {} Bar.cs: #define Y #if X #error Bang! #endif #if !Y #error Bang! #endif class... more 11/21/2014 1:00:42 PM

people

Cannot find symbol method

Upon compiling, I get the error of cannot find symbol - method add(java.lang.String). The goal of the code so far is just to add a new flavour to the ArrayList. I am using the...
Jon Skeet
people
quotationmark

Look at the code: public void newFlavour(String flavours) { flavours.add(flavours); } The parameter flavours is shadowing your field flavours, so the compiler is trying to find an add method in String, not ArrayList. You... more 11/21/2014 11:45:21 AM

people