• Saves Valuable Time
  • Trusted Accuracy since 2004
  • 15-Day Money-Back Guarantee

Java Equivalent to VB Casts

The closest equivalent to the standard VB casting operators (CType and the corresponding CInt, CStr, etc.) are calls to the 'parse' methods (Integer.parseInt, Short.parseShort, etc.) if the argument is a string, otherwise they are converted to the standard Java casting operator.

The behavior of both the 'parse' methods and the standard Java casting operator are subtly different from the VB casting operators though, so you should always test the behavior of your converted Java code.

The Java equivalent to VB's DirectCast is the standard Java casting operator.

The VB TryCast operator conversion always uses the Java instanceof operator.

VB Java
x = TryCast(y, z) x = y instanceof z ? (z)y : null;

Use VB to Java Converter to convert from VB to Java.     

Additional resource: VB.NET and Java Equivalents

Copyright © 2004 – 2021 Tangible Software Solutions, Inc.