Can we initialize fields of a class in the same line as instantiating it?
public class LinkedQueueOfStrings {
private Node first;
private Node last;
private class Node
{
private String element;
private Node next;
}
public void enqueue(String s)
{
last.next = new Node(){element = s};
//Is there a way can do like this??
}
}
Is there a way we can we do like this,
last.next = new Node(){first = s};
assuming we don't have a constructor which initializes node with an element?
Stringisn't aNode.