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

VB Equivalent to Java Enums

Simple enums in Java have simple equivalents in VB:

Java VB
public enum Simple
Public Enum Simple
End Enum

More complex enums in Java unfortunately have exceedingly complex equivalents in VB:

Java VB
public enum Complex

    private final String value;

    Complex(String enumValue)
        this.value = enumValue;

    public void InstanceMethod()
Imports System.Collections.Generic

Public NotInheritable Class Complex
    Public Shared ReadOnly FOO As New Complex("FOO", InnerEnum.FOO, "Foo")
    Public Shared ReadOnly BAR As New Complex("BAR", InnerEnum.BAR, "Bar")

    Private Shared ReadOnly valueList As IList(Of Complex) = New List(Of Complex)()

    Shared Sub New()
    End Sub

    Public Enum InnerEnum
    End Enum

    Public ReadOnly innerEnumValue As InnerEnum
    Private ReadOnly nameValue As String
    Private ReadOnly ordinalValue As Integer
    Private Shared nextOrdinal As Integer = 0

    Private ReadOnly value As String

    Friend Sub New(ByVal name As String, ByVal thisInnerEnumValue As InnerEnum, ByVal enumValue As String)
        Me.value = enumValue

        nameValue = name
        ordinalValue = nextOrdinal
        nextOrdinal += 1
        innerEnumValue = thisInnerEnumValue
    End Sub

    Public Sub InstanceMethod()
    End Sub

    Public Shared Function values() As IList(Of Complex)
        Return valueList
    End Function

    Public Function ordinal() As Integer
        Return ordinalValue
    End Function

    Public Overrides Function ToString() As String
        Return nameValue
    End Function

    Public Shared Function valueOf(ByVal name As String) As Complex
        For Each enumInstance As Complex In Complex.valueList
            If enumInstance.nameValue = name Then
                Return enumInstance
            End If
        Throw New System.ArgumentException(name)
    End Function
End Class

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

Additional resource: VB.NET and Java Equivalents

Copyright © 2004 – 2019 Tangible Software Solutions, Inc.