Electron optics introducing the optical concepts into the electronic system unifies the propagation and interference behaviors of different waves and promises nontrivial electronic applications. Due to the high mobility of massless Dirac fermions (MDFs), Dirac materials are suitable for the exploration of optics-like phenomena, in which the Goos-Hanchen shift is an outstanding example. The Goos-Hanchen shift has been studied very well for isotropic MDFs, e.g., in graphene, the relevant generalization to anisotropic MDFs is interesting but lacking. Here, we study the Goos-Hanchen shift of the reflected MDFs by n p junctions based on 8-Pmmn borophene, in which MDFs are tilted. The Goos-Hanchen shift of tilted MDFs has a strong dependence on the junction direction, providing an additional tunability. Accounting for two valleys coupled by the time-reversal symmetry, the valley-contrasting Goos-Hanchen shift is demonstrated, this feature favors the use of 8-Pmmn borophene n p junctions in valleytronics. This study is helpful to understand the anomalous shift of tilted MDFs along the longitudinal interface of np junctions, and implies the potential applications in valleytronics of 8-Pmmn borophene junctions. Published under an exclusive license by AIP Publishing.