How to deal with very long lstinline-phrases like long class names?

Or, to make things fully automatic (in your case):

\documentclass{minimal}
\usepackage{listings}
\begin{document}
\lstinline[
  literate={A}{A}{1\discretionary{}{}{}}
           {B}{B}{1\discretionary{}{}{}}
           {C}{C}{1\discretionary{}{}{}}
           {D}{D}{1\discretionary{}{}{}}
           {E}{E}{1\discretionary{}{}{}}
           {F}{F}{1\discretionary{}{}{}}
           {G}{G}{1\discretionary{}{}{}}
           {H}{H}{1\discretionary{}{}{}}
           {I}{I}{1\discretionary{}{}{}}
           {J}{J}{1\discretionary{}{}{}}
           {K}{K}{1\discretionary{}{}{}}
           {L}{L}{1\discretionary{}{}{}}
           {M}{M}{1\discretionary{}{}{}}
           {N}{N}{1\discretionary{}{}{}}
           {O}{O}{1\discretionary{}{}{}}
           {P}{P}{1\discretionary{}{}{}}
           {Q}{Q}{1\discretionary{}{}{}}
           {R}{R}{1\discretionary{}{}{}}
           {S}{S}{1\discretionary{}{}{}}
           {T}{T}{1\discretionary{}{}{}}
           {U}{U}{1\discretionary{}{}{}}
           {V}{V}{1\discretionary{}{}{}}
           {W}{W}{1\discretionary{}{}{}}
           {X}{X}{1\discretionary{}{}{}}
           {Y}{Y}{1\discretionary{}{}{}}
           {Z}{Z}{1\discretionary{}{}{}}
!ThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreakThisIsAVeryLongExampleClassNameAndItHasNoLineBreak!

\end{document}

Obviously, this should be put in a style...

(To get - at the end of the line, use \discretionary{-}{}{}. 26 times :-)


The cool trick from the question you have cited can be used to define a conditional line break:

\documentclass{minimal}
\usepackage{listings}
\begin{document}
Bla bla blabla blabla bla bla blabla bla blabla bla blabla
bla blabla bla blablablabla bla
\lstinline[literate={\\\-}{}{0\discretionary{-}{}{}}]!ThisIsAVeryLong\-Example\-ClassNameAndItHasNoLineBreak!
bla blabla blabla blabla bla
\end{document}

P.S. I guess the \\ as the second arg of \discretionary in the cited question was as mistake? Anyway, the above works for me.