The effect on adaptive immunity are often stronger when contracting the flu than for getting the flu vaccination. The backside of this is that the flu is a quite dangerous disease which could end fatally, so getting the vaccine is always preferrable.
Getting infected by a specific flu strain (or receive a vaccination against it) generates specific immunity against this strain. If it mutates to strong or you get infected with another strain, you will have no immunity (and will have to develop a new immune response.
It seems that immunity against the flu can be livelong (against this strain) after you went through an infection and survived it. There are two studies showing long term response against antigens from the 1918 flu pandemic. The first (summarized in reference 1, the original article is reference 2) shows specific antibodies against the reconstructed haemagglutinin protein (H1) from the 1918 virus strain.
Serum from people born 1915 or before showed specific activity against this virus antigen, even more than 90 years after the infection.
The second study analyzes cross-reactivity of antibodies against the 2009 A/H1N1 pandemic flu strain. Here the cross reactivity of people born before 1930 was the highest - the 1918 strain (with which these people most likely had contact) was also a H1N1 virus. Although these viruses mutated between 1918 und 2009, there is still enough similarity that they are recognized by H1N1 specific antibodies (see reference 2).
A study which compared antibodies responses of people who contracted the 2009 flu against people who where vaccinated against it, showed that the antibody response was more longlasting in the people who got the infection (see reference 3).
So I think it is safe to say that the immune response is stronger after the infection compared to the vaccination, but the vaccination is much safer.
- How Long Does Flu Immunity Last?
- Neutralizing antibodies derived from the B cells of 1918 influenza
- Antibody Dynamics of 2009 Influenza A (H1N1) Virus in Infected
Patients and Vaccinated People in China