I'm not very familiar with Python, so when I met this code, there are a few things not quite clear to me. Here is the code:
class TypeVariable(object):
#A type variable standing for an arbitrary type.
#All type variables have a unique id, but names are only assigned lazily,
#when required.
next_variable_id = 0
def __init__(self):
self.id = TypeVariable.next_variable_id
TypeVariable.next_variable_id += 1
self.instance = None
self.__name = None
next_variable_name = 'a'
@property
def name(self):
#Names are allocated to TypeVariables lazily, so that only TypeVariables present
if self.__name is None:
self.__name = TypeVariable.next_variable_name
TypeVariable.next_variable_name = chr(ord(TypeVariable.next_variable_name) + 1)
return self.__name
Why does def __init__(self): not have name as a parameter but in the above code there is self.__name = None?
Also, what does self.instance mean, because I don't recall that there is an attribute called instance.
Can someone please help me understand what this code does, and if a java version can be provided will be much appreciated since I'm more familiar with Java. Thanks