Don't knock masturbation. It's sex with someone you love.
A joke about solitary pleasure turns into a small defense of liking yourself. The humor depends on a twist: the line sounds like a defense of masturbation, but it also hints that the person speaking has a complicated, self-absorbed relationship with love. It fits Woody Allen's comic persona, the anxious, neurotic, self-mocking urbanite who treats his own desires as both embarrassing and absurd. Strictly speaking, it is a line from his film Annie Hall, spoken by his character in the first person ("someone I love"), so it is better read as characterization than as a personal philosophy.
Beneath the gag lies a gentler idea found in modern, post-Freudian attitudes: sexuality is a normal part of life, and shame about it does more harm than the thing itself. Self-love, in the sense of basic goodwill toward yourself, is not a poor substitute for connection but a foundation for it.
In practice, someone might apply this by dropping the habit of treating time alone as a failure. A single person on a Saturday night could cook a nice dinner and enjoy their own company, without apologizing for it or feeling like they are merely waiting for someone else.