Java Class.cast() vs. cast operator

I’ve only ever used Class.cast(Object) to avoid warnings in “generics land”. I often see methods doing things like this: @SuppressWarnings(“unchecked”) <T> T doSomething() { Object o; // snip return (T) o; } It’s often best to replace it by: <T> T doSomething(Class<T> cls) { Object o; // snip return cls.cast(o); } That’s the only use … Read more

How do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit?

The -Wno-unused-variable switch usually does the trick. However, that is a very useful warning indeed if you care about these things in your project. It becomes annoying when GCC starts to warn you about things not in your code though. I would recommend you keeping the warning on, but use -isystem instead of -I for … Read more

“Delegate subtraction has unpredictable result” in ReSharper/C#?

Don’t be afraid! The first part of ReSharper’s warning only applies to removing lists of delegates. In your code, you’re always removing a single delegate. The second part talks about ordering of delegates after a duplicate delegate was removed. An event doesn’t guarantee an order of execution for its subscribers, so it doesn’t really affect … Read more

Custom Compiler Warnings

This is worth a try. You can’t extend Obsolete, because it’s final, but maybe you can create your own attribute, and mark that class as obsolete like this: [Obsolete(“Should be refactored”)] public class MustRefactor: System.Attribute{} Then when you mark your methods with the “MustRefactor” attribute, the compile warnings will show. It generates a compile time … Read more

Objective-C implicit conversion loses integer precision ‘NSUInteger’ (aka ‘unsigned long’) to ‘int’ warning

The count method of NSArray returns an NSUInteger, and on the 64-bit OS X platform NSUInteger is defined as unsigned long, and unsigned long is a 64-bit unsigned integer. int is a 32-bit integer. So int is a “smaller” datatype than NSUInteger, therefore the compiler warning. See also NSUInteger in the “Foundation Data Types Reference”: … Read more