“Convert” Option[x] to x
If you have x as Option[Long], x.get will give you Long.
If you have x as Option[Long], x.get will give you Long.
If you want full type safety, I don’t think you can do better without some kind of wrapper classes. But, why not make those classes inherit/implement the original generic versions, like this: public class FooBBQ extends Foo<Bar<Baz,Qux>> { … } This eliminates the need for toGeneric() method, and it is more clear, in my opinion, … Read more
I worked up a similar example that fails the same way: using System; using System.Runtime.CompilerServices; public class Program { static void Main() { Console.Write(Verify(Test.Create())); Console.ReadLine(); } //[MethodImpl(MethodImplOptions.NoInlining)] static bool Verify(IDisposable item) { return item is Test; } struct Test : IDisposable { public void Dispose() { } public static Test Create() { return new Test(); … Read more
For me (using Java 1.6.0_26), the first snippet gives the same exception as the second one. The reason is that the Arrays.asList(..) method does only return a List, not necessarily an ArrayList. Because you don’t really know what kind (or implementation of) of List that method returns, your cast to ArrayList<String> is not safe. The … Read more
Your function has a couple of smallint parameters. But in the call, you are using numeric literals that are presumed to be type integer. A string literal or string constant (‘123’) is not typed immediately. It remains type “unknown” until assigned or cast explicitly. However, a numeric literal or numeric constant is typed immediately. The … Read more
Try to do it like this: AVG(Cast(e.employee_level as Float)) as avg_level Also i found this topic where you can find some another approach but i not used its and don’t know exactly whether works or not.
You can cast through the untyped List interface: List<A> a = new ArrayList<A>(); List<B> b = (List)a;
In C#, unlike Java, enums are not checked. You can have any value of the underlying type. This is why it’s pretty important to check your input. if(!Enum.IsDefined(typeof(MyEnum), value)) throw new ArgumentOutOfRangeException();
Function style casts bring consistency to primitive and user defined types. This is very useful when defining templates. For example, take this very silly example: template<typename T, typename U> T silly_cast(U const &u) { return T(u); } My silly_cast function will work for primitive types, because it’s a function-style cast. It will also work for … Read more
From the documentation (emphasis mine): Cast a value to a type. This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible). The “casting” only takes place in the type-checking … Read more