This will work, but there is a specific type of fitting which is made for this purpose called a trap adapter. One end glues directly to the stub, and the other has a compression fitting that will accept the trap.
There is a big advantage of using the trap adapter over gluing. It allows easy removal of the entire trap for renovations, or maintenance. Lets say that you have the trap glued in and you want to replace the sink or counter. You would have a tough time removing the trap, and it would involve extensive plumbing work. With the trap adapter, all you would have to do is unscrew it from the wall, and from underneath the sink and the entire assembly can come out in one piece.
The adapters are also fairly inexpensive, and may even cost less than a comparable fernco fitting. The adapter is superior because it is nearly flush with the wall, and easier to remove.
Below are some examples of trap adapters. They are available in 1.25" and 1.5", which covers residential use. They are also available in PVC and ABS.