Quite often in Java we see algorithms like:
MyObject currentObject = null 
for(MyObject oldObject: objects){
    if(currentObject != null) doSomething
    else doSometing
    currentObject = oldObject  
} 
I'm trying to implement this in Scala:
var currentObject: MyObject = null
for(oldObject <- objects){
    if(currentObject != null) doSomething
    else doSometing
    currentObject = oldObject  
} 
However, I'm receiving a Wrong Forward reference compilation error.
I guess the problems is with the initialisation as null of the currentObject?
UPDATED:
Here the actual code:
var protCoord:Coordinates     = new Coordinates()
var prevprotCoord:Coordinates = new Coordinates()
var coordMap = mutable.Map[Coordinates, GenomeCoordinates]()
var protein:EnsemblProteinEntry = null
var codingLength = 0
for (gtfEntry <- gtfEntries.toStream) {
  if (gtfEntry.isGene)
    mapping.addGene(new GTFGeneEntry(gtfEntry))
  if(gtfEntry.isTranscript){
    mapping.addTranscriptID(gtfEntry)
  if(protein != null) protein.multiMapCoordinates = coordMap // **I'm receiving the error here** 
    var protein = fastaEntries.getOrElse(gtfEntry.transcriptIdentifier, null)
  if(protein == null)
    protein = new EnsemblProteinEntry()
  protCoord = new Coordinates()
  prevprotCoord = new Coordinates()
  coordMap = mutable.Map[Coordinates, GenomeCoordinates]()
  codingLength = 0
}
Thanks in advance.
 
     
    