Instantiate to Class

public class A : MonoBehaviour {}


public void create(A prefab) // prefab not null.
{
   A a = MonoBehavior.Instantiate(prefab.gameObject) as A;

   // a is null now!
}

How can I Instantiate from a prefab and instead of putting the returned value into a GameObject I put it into a class type.

I rather not use this if possible:

GameObject g = Instantiate(prefab.gameObject) as GameObject;
A a = g.GetComponent<A>();

A a = (Instantiate(prefab.gameObject) as GameObject).GetComponent();

or if you really want to experiment you could try

A a = Instantiate(prefab.gameObject.GetComponent<A>()) as A;

but I’ll be surprised if that actually works.

A a = (A)GameObject.Instantiate(prefab);