It's not possible in Julia at the moment. There's an issue for it. <https://github.com/JuliaLang/julia/issues/269> I think the main options are:
- Don't declare the types. This may make it slower, but depending on the use case it might not be a big deal - Use parametric types, i.e. type Node{T} edges::Vector{T} end type Edge{T} node::T end On Friday, August 26, 2016 at 1:38:38 PM UTC-4, varu...@gmail.com wrote: > > Hello all, > > I'm making a transition from Python to Julia and in the process, I've > encountered a small difficulty. While in python, i declared three classes > as follows: > > class PHY_NODES: > def __init__(self, nodeID, nodenum, x, y, demands): > self.id = nodeID > self.nodenum = nodenum > self.x = x > self.y = y > self.inEdges = [] > self.outEdges = [] > self.demands = demands > > def __str__(self): > return "Physical Node ID: nodenum: %4d x: %.3f y: %.3f" %(self.id, > self.nodenum, self.x, self.y ) > > def addInEdge(self, edge): > self.inEdges.append( edge ) > > def addOutEdge(self, edge): > self.outEdges.append( edge ) > > > class PHY_LINKS: > def __init__(self, linkID, source, destination, SourceID, > DestinationID,): > self.linkID = linkID > self.source = source > self.destination = destination > self.SourceID = SourceID > self.DestinationID = DestinationID > > > def __str__(self): > return "Physical Link ID: %4d source: %s destination: %s SourceID: > %4d DestinationID: %4d " %(self.linkID, self.source, self.destination, > self.SourceID, self.DestinationID, ) > > > class DEMAND: > def __init__(self, PoP_bdw_up, PoP_stor, PoP_pro, MME_bdw_up, > MME_stor, MME_pro,demandID): > self.PoP_bdw_up = PoP_bdw_up > self.PoP_stor = PoP_stor > self.PoP_pro = PoP_pro > self.MME_bdw_up = MME_bdw_up > self.MME_stor = MME_stor > self.MME_pro = MME_pro > self.demandID = demandID > > > def __str__(self): > return " PoPbdwup: %.3f PoPstor: %.3f PoPpro: %.3f MMEbdwup: %.3f > MMEstor: %.3f MMEpro: %.3f, self.demandID ) > > However, I have some trouble when replicating the same in Julia especially > due to the nested classes in PHY_NODES (self.inEdges as well as > self,demands) > > The Julia version of the Phy_Node class is as below: > > type PhysicalNodes > ID:Int > name:String > x: Float > y:Float > inEdges: ? > outEdges: ? > demands: ? > end > > I don't how to declare the inEdges, outEdges and demands here. Could you > please help me with this? > >